Html.Raw 无意中拆分了字符串



我正在开发一个页面,客户可以在其中为他们销售的商品编写自己的描述。他们可以为此使用 html 标记。

视图中的代码如下所示:

@Html.Raw("<p class='description short'>" + shopItem.ShortDescription + "</p>")

问题是,这被分成两个p标签:

<p class="description short"></p>

下面是 shopItem.ShortDescription:

<p><em><strong>Title</strong></em></p>

我也试过

<p class="description short">@Html.Raw(shopItem.ShortDescription)</p>

但这会导致相同的行为。

确定我错过了或没有看到什么。那么,该代码片段有什么问题呢?

我相信

这里的问题是你不能嵌套p元素。如果您仅使用 html 尝试它仍然不起作用,但例如这工作正常

@{     
    var shopItem = "<em><strong>Title</strong></em>";
}
@Html.Raw("<p class='description short'>" + shopItem + "</p>")

最新更新