.NET MVC - 如何分配一个类来Html.LabelFor? [英] .NET MVC - How to assign a class to Html.LabelFor?
本文介绍了.NET MVC - 如何分配一个类来Html.LabelFor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这code
<%= Html.LabelFor(model => model.Name) %>
产生这样的
<label for="Name">Name</label>
不过,我想这
<label for="Name" class="myLabel">Name</label>
你是怎么做到的?
How do you do that?
推荐答案
好吧,查看源(System.Web.Mvc.Html.LabelExtensions.cs)这个方法,似乎没有成为一个方式在ASP.NET MVC的的HtmlHelper做到这一点。我认为最好的方法是创建你自己的HtmlHelper或做这个特定的标签以下内容:
Okay, looking at the source (System.Web.Mvc.Html.LabelExtensions.cs) for this method, there doesn't seem to be a way to do this with an HtmlHelper in ASP.NET MVC 2. I think your best bet is to either create your own HtmlHelper or do the following for this specific label:
<label for="Name" class="myLabel"><%= Model.Name %></label>
这篇关于.NET MVC - 如何分配一个类来Html.LabelFor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文