Most MVC Html helpers allow the caller to specify htmlAttributes as either an anonymous object or an IDictionary<string, object>. The overload that takes a dictionary is convenient as it makes it possible to easily merge attributes from different sources.<br /><br />WebGrid.GetHtml (and WebGrid.Table) only accept an anonymous object.<br /><br />These methods should be enhanced either by adding appropriate overloads, or by checking for a dictionary, e.g.:<br /><br /> ... Table(... object htmlAttributes = null)<br /> { <br /> IDictionary<string, object> dictionary = htmlAttributes as IDictionary<string, object>;<br /> if (dictionary == null && htmlAttributes != null)<br /> {<br /> dictionary = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);<br /> }<br /> ... etc ...<br /> }
↧