In asp.net mvc I always see the built in html helpers they always have object htmlAttirbutes.
Then I usually do new {@id = \"test\", @class=\"myClass\"}.
How do
you can transform the object htmlAttirbutes to an attribute/value string representation like this :
var htmlAttributes = new { id="myid", @class="myclass" };
string string_htmlAttributes = "";
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(htmlAttributes))
{
string_htmlAttributes += string.Format("{0}=\"{1}\" ", property.Name.Replace('_', '-'), HttpUtility.HtmlAttributeEncode(property.GetValue(htmlAttributes).ToString()));
}
PropertyDescriptor belong to the class System.ComponentModel