EF MVC RAZOR:如何解码PartialView输出的HTML编码字符串?

Lar*_*rry 7 html asp.net-mvc encode decode asp.net-mvc-3

我正在使用带有Razor的EF4 + MVC 3.

我有以下内容ActionResult,它将Dictionary<string,string>部分视图呈现出来.

行动

public ActionResult combotest()
{
    Dictionary<string, string> r = new Dictionary<string, string>();
    r.Add("<> ''", "T");
    ...
    return PartialView("_mypartial", r);
}
Run Code Online (Sandbox Code Playgroud)

现在,包含在Model.Key值中的特殊字符是HTML编码,而我想将它们用作纯文本.例如<> '',呈现为&lt;&gt; &#39;&#39;.

我试图将它们与转换WebUtility.HtmlDecodeServer.HtmlDecode没有成功:

部分视图(_mypartial):

<select>
    <option value=''></option>
    @foreach (KeyValuePair<string,string> value in (Dictionary<string, string>)Model) 
    {
        <option value="@WebUtility.HtmlDecode(value.Key)">@value.Value
     </option>
    }
</select>
Run Code Online (Sandbox Code Playgroud)

你可以帮帮我吗?String.Replace如果可能的话,我会避免使用.

Jam*_*ago 20

要显示未编码的文本,您可以使用 @Html.Raw(value.key)