我的 Razor Helper 文件中有以下代码
@helper MakeNoteBlank(string content)
{
string msg = "";
if(content == null)
{
msg = " ";
}
else
{
msg = content;
}
<div class="note">
<p>
@Html.Raw(msg)
</p>
</div>
}
代码在执行时失败,并显示 @Html.Raw(..) 语句,表明 “你调用的对象是空的。”
如果我删除@Html.Raw(..)并直接输出'msg'那么就没有问题。
我做错了什么?
最佳答案
使用@(new HtmlString())代替@Html.Raw()
关于asp.net-mvc - HTML.Raw 的 MVC @helper 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28573477/