使用MVC3中的Html.LabelFor在表单标签中锚定标记

时间:2012-03-15 13:57:51

标签: asp.net-mvc-3 label

我想完成像

这样的事情
<label for="AgreedToTherms">
I agree to the <a href="therms-and-conditions">Therms and conditions</a>
</label>

这是否允许根据HTML标准? 在视图中使用标准的Html帮助器

@Html.LabelFor(model => model.AgreedToTherms)

我尝试使用在labeltext中添加html,但是这个文本获得了html编码

1 个答案:

答案 0 :(得分:11)

你可以这样做:

@MvcHtmlString.Create(HttpUtility.HtmlDecode(
    Html.LabelFor(m=>m.AgreedToTherms).ToString()))

(OR)

@Html.Raw(@HttpUtility.HtmlDecode(
    Html.LabelFor(m=>m.AgreedToTherms).ToString()))