我使用EF4 + MVC 3剃须刀。EF MVC RAZOR:如何解码PartialView输出的HTML编码字符串?
我有以下ActionResult
,这使得一个Dictionary<string,string>
成的局部视图。
ACTION
public ActionResult combotest()
{
Dictionary<string, string> r = new Dictionary<string, string>();
r.Add("<> ''", "T");
...
return PartialView("_mypartial", r);
}
现在,包含入Model.Key
值特殊字符是HTML编码,而我想用它们为纯文本。例如<> ''
呈现为<> ''
。
我试图将它们与WebUtility.HtmlDecode
或Server.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>
你能帮助我吗?如果可能,我会避免使用String.Replace
。
你可以指定出了什么问题与其他两种方法? – linkerro 2012-02-16 12:10:31