public static RouteValueDictionary AnonymousObjectToHtmlAttributesMvc2(this HtmlHelper htmlHelper, object htmlAttributes)
{
//originally copied from MVC3 source
if (htmlAttributes is RouteValueDictionary)
return (RouteValueDictionary)htmlAttributes; //<- this is not in the base MVC3 version - Too bad.
if (htmlAttributes is IDictionary<string, object>)
return new RouteValueDictionary((IDictionary<string, object>)htmlAttributes); //<- this is not in the base MVC3 version - Too bad.
var result = new RouteValueDictionary();
if (htmlAttributes != null)
{
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(htmlAttributes))
{
result.Add(property.Name.Replace('_', '-'), property.GetValue(htmlAttributes));
}
}
return result;
}