19
ASP.NET MVC HtmlHelper methods and CSS class
4 Comments · Posted by veggerby in ASP.NET MVC
If you in ASP.NET MVC use a Html helper method to render out e.g. an input box:
Sometimes you might need to add an CSS class attribute to your input box (this should be a fairly standard thing). For this there exist overload methods that takes a “htmlAttributes” parameter of type object. Now my experience with this is somewhat similar to Ayende Rahien experience – although I have not begun banging my head against the wall out of frustration. This is not a rant, I love ASP.NET MVC, I just had an experience with something simple that was hard to figure out because of some of the design decisions – not that they are bad, they can just be confusing – especially with the lack of documentation at the current stage (yes, I know it is just a beta). So if you try this:
You will (of course) get a compiler error, since “class” is a keyword and cannot be used like this. So how do you specify the class? Well, like this:
Just for future reference
ASP.NET · ASP.NET MVC · reference

ASP.NET MVC Archived Blog Posts, Page 1 · November 21, 2008 at 17:02
[...] to VoteASP.NET MVC HtmlHelper methods and CSS class (11/19/2008)Wednesday, November 19, 2008 from noseyIf you in ASP.NET MVC use a Html helper method to render out [...]
Tom · December 9, 2008 at 06:39
Thanks, I’ve been looking for the answer to this!
Dimi3 · January 21, 2009 at 12:00
Thanks!
Htmlhelpers Css Classes - asp.net mvc « EricDotNet · January 29, 2009 at 17:18
[...] Thanks to this blogpost for the answer: http://blog.veggerby.dk/2008/11/19/aspnet-mvc-htmlhelper-methods-and-css-class/ [...]