Asp.net mvc Razor对引用的html属性进行编码

Asp.net mvc Razor对引用的html属性进行编码,asp.net-mvc,razor,Asp.net Mvc,Razor,我希望使用以下结构有条件地向客户端呈现适当的HTML: <input type="button" value="Foo" @(string.IsNullOrEmpty(Model.Identifier) ? string.Format("title={0} disabled=disabled", "Lorem ipsum") : "onclick=window.open('http://www.google.com'); return false;") /> 这是我得到的输出:

我希望使用以下结构有条件地向客户端呈现适当的HTML:

<input type="button" value="Foo" @(string.IsNullOrEmpty(Model.Identifier) ? string.Format("title={0} disabled=disabled", "Lorem ipsum") : "onclick=window.open('http://www.google.com'); return false;") />

这是我得到的输出:

<input type="button" value="Foo" title=&quot;Lorem ipsum&quot; disabled=disabled />


我尝试了许多Html.Raw()构造,但似乎没有任何帮助。如何使用引号而不是HTML实体正确输出未编码的HTML?

试试这个。我试过了,它对我有用。区别在于单个引号和Html.Raw围绕整个内容

<input type="button" value="Foo" @Html.Raw(string.IsNullOrEmpty(Model.Identifier) ? string.Format("title='{0}' disabled='disabled'", "Lorem ipsum") : "onclick='window.open(\"http://www.google.com\"); return false;'") />

我认为添加单引号就足够了

..."title='{0}' disabled='disabled'"...