Mvc Generic Html By Anonymous Type

post_id: 99 / post_date: 2012-02-03

There is no equivalent for asp's create generichtmlcontrol.
In some rare cases, it may make sense to do this. Esp when the generation of html is mixed with @ directives inside "" for attrs.

*Note that class is a keyword and cant be used as property name in the anonymouse type. So we use CssClass instead and make the Extension method aware of this possibility.

@Html.StartTag("div", new { id ="name", CssClass = "cls", style= @Model.Styles})

UPDATE (Feb 10th): You can say @class to use the reserved keyword. So the code atts["class"] = atts["CssClass"]; is redundant

[iframe src=""]