开发者

Editing the attributes genereted from @Html.EditorFor

开发者 https://www.devze.com 2023-03-04 17:42 出处:网络
I wonder if its possible to edit the attributes value that the@Html.EditorFor(model => item.Title) is generating

I wonder if its possible to edit the attributes value that the @Html.EditorFor(model => item.Title) is generating

the @Html.EditorFor(model => item.Title) would generate this:

<input class="text-box single-line" id="item_Title" name="item.Title" type="text" value="Avatar" />

i wonder if its possible to edi开发者_如何学运维t the id attribut?

Thanks!


I don't think you can edit the id since the point of EditorFor is that it's "bound" to the model's property that you're applying it to. If you need a different id, you could try making your own text box with Html.TextBox.


Create your own Editor template to custom render whatever you want. See: http://www.codecapers.com/post/Display-and-Editor-Templates-in-ASPNET-MVC-2.aspx You then have control over how the editor html is emitted. you MAY though have to do a bit of lambda parsing magic to get the model variable name. I'd have to research that more - just wanted to give a pointer here in case no one else replied.

In this case though, you 'MAY' have to instead write your own extension method that takes the lambda and creates the names based off that lambda. You can see how the lambda is parsed as an example here: http://blogs.planetcloud.co.uk/mygreatdiscovery/post/Creating-tooltips-using-data-annotations-in-ASPNET-MVC.aspx

this all may not be too helful.. but want to provide at least something else : )

0

精彩评论

暂无评论...
验证码 换一张
取 消