Back to list
Views:   42.6K
Replies:  2

Passing HTML Attributes into EditorFor in MVC 3

I want to pass a @class =  attribute into one of my EditorFor() calls.  Something like this:

<%= Html.EditorFor(model => model.Name, new { @class = "myclass" }) %>
I cannot find an EditorFor() method signature that supports this.

This is a one-off so I don't want to dig deep and get into templates, etc.
How do I do this?
Bogusław Dobrogost, Jul 19, 2011
Reply 1
Is there any reason you can't use TextBoxFor()?  Or any of the other specific HTML Helpers?  They have overloads for HTML attributes.
King Wilder, Jul 24, 2011
Reply 2
There is no overload for EditorFor that takes this kind of argument...

Alternate solution at

Also check this alternative....

Hope this helps!
Rajesh Pillai, Jul 23, 2011
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.