我的数据库中有包含要点的记录。当我用项目符号检索数据并将其显示在 Razor 页面视图上时,它会显示如下:
Measures 24”x10”x12” or 2,800 cubic inches of storage space 3 layer laminated polyester waterproof fabric Commercial grade zipper Reinforced steel frame closure Extra heavy duty bottom panel 5 exterior pockets 6 interior pockets Writable name plate
但我希望他们像这样展示它们:
Measures 24”x10”x12” or 2,800 cubic inches of storage space
3 layer laminated polyester waterproof fabric
Commercial grade zipper
Reinforced steel frame closure
Extra heavy duty bottom panel
5 exterior pockets
6 interior pockets
Writable name plate
我该如何处理这个问题。我对如何解决这个问题有点困惑。
有什么建议吗?
为了提供更多上下文,用户可以复制并粘贴到描述框中,就像我截图的那样(见下文)。一旦他们保存了产品,在我看来,它就会变成一个字符串,如下所示。我知道有 3 条记录显示,但我的问题仍然存在。当用户复制和粘贴时,它显示正确的格式,但在检索它时,它显示单个字符串。
您可以遵循的简单演示:
查看
@model string
@{
var bulletPoints = Model?.Split('', StringSplitOptions.RemoveEmptyEntries);
}
<ul>
@foreach (var point in bulletPoints)
{
<li>@point.Trim()</li>
}
</ul>
控制器
public IActionResult Index()
{
string data = " Measures 24”x10”x12” or 2,800 cubic inches of storage space 3 layer laminated polyester waterproof fabric Commercial grade zipper Reinforced steel frame closure Extra heavy duty bottom panel 5 exterior pockets 6 interior pockets Writable name plate";
return View("Index",data);
}