How to pass an object to HTML attributes? For example I have the following code:
var attrs = new { id = \"myid\", style = \"color: Red;\" };
<
Here's how to do this conversion :
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('_', '-'), property.GetValue(htmlAttributes));
}
PropertyDescriptor belong to the class System.ComponentModel