我试图在我的 var 中添加多个空格,但它被减少到一个空格或者它呈现出来 & nbsp;照原样。我试过使用 & nbsp;和 %20 任何人有任何其他想法?
ViewBag.Subheading = "Bringing to light";
我希望它看起来像这样
重见天日
最佳答案
ViewBag.Subheading = "Bringing to light".Replace(" ", " ");
和
@Html.Raw(ViewBag.Subheading)
或者你可以这样做:
public static MvcHtmlString DisplayAndRetainSpaces(this HtmlHelper html, string value)
{
return MvcHtmlString.Create(value.Replace(" ", " "));
}
然后像这样调用它:
@Html.DisplayAndRetainSpaces(ViewBag.Subheading)
关于asp.net-mvc - 在var中渲染多个空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6286266/