Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将MvcHtmlString与jQuery模板一起使用-what';正确的razor语法是什么?_C#_Asp.net Mvc_Jquery Templates_Mvchtmlstring - Fatal编程技术网

C# 将MvcHtmlString与jQuery模板一起使用-what';正确的razor语法是什么?

C# 将MvcHtmlString与jQuery模板一起使用-what';正确的razor语法是什么?,c#,asp.net-mvc,jquery-templates,mvchtmlstring,C#,Asp.net Mvc,Jquery Templates,Mvchtmlstring,我有这样的jQuery模板: <script id="msgTmpl" type="text/x-jquery-tmpl"> <li><span style="color:Black"><strong>${user.name}</strong> (${datetime})</span><br/><span>${richMessage}</span></li> </

我有这样的jQuery模板:

<script id="msgTmpl" type="text/x-jquery-tmpl">
    <li><span style="color:Black"><strong>${user.name}</strong> (${datetime})</span><br/><span>${richMessage}</span></li>
</script>
richMessage可以包含HTML标记。

我希望它被解释为HTML,而不是显示为标签序列

我知道必须使用MVCHtmlString.Create,但我无法理解正确的语法

我还尝试在richMessage属性上使用[AllowHtml]属性,但没有成功

我的问题是:如何使用MvcHtmlString.Create允许MVC正确显示richMessage?

您应该使用jQuery模板的语法。这与MVC端的
@Html.Raw
类似

<span>{{html richMessage}}</span>
{{html richMessage}

这将把
richMessage
属性的内容输出到
span
标记中,而不转义HTML。

尝试使用
{{HTML richMessage}}
而不是
${richMessage}
。您的问题在于,
${}
默认情况下对值进行编码。

非常感谢,您为我节省了很多时间:)
<span>{{html richMessage}}</span>