Monday, February 08, 2010

MVC's HtmlAttributes Parameter

In MVC's model it is very easy to generate HTML tags, or XHTML elements, as I believe they prefer to be known these days.

What wasn't so obvious was the optional htmlAttributes parameter, available in all the Html.TextBoxFor(...) Html.LabelFor(...) etc etc.

My question was, "How do I use this, what's it for, why, when, where, who, whether, whence, etc?"

Yeah, I'm not so great at forming questions sometimes. But the answer came in the form of Rob Conery's blog entry:
And so I've learnt that you can simply have disabled="disabled" in a new {} and the ...For adds the values as attributes to your HTML element. Read Rob's article for a better description.

However, if you're still having trouble with this (eg: ActionLink doesn't seem to link certain htmlAttributes assignments) you can check out this post at stackoverflow:
Top notch.

Yes, I need to get the code embedding sorted on this 'ere blog thingy...

1 comment:

  1. First link is dead, change to: