Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to extend the HtmlHelper with the IDictionary<string, object> overload?
    primarykey
    data
    text
    <p>I created an extension method for the HtmlHelper which works very well. Now I need to create the overload that receives an IDictionary so I can add a css class to it so I tried the following:</p> <pre><code>public static MvcHtmlString EnumDropDownListFor&lt;TModel, TEnum&gt;(this HtmlHelper&lt;TModel&gt; htmlHelper, Expression&lt;Func&lt;TModel, TEnum&gt;&gt; expression) { return EnumDropDownListFor(htmlHelper, expression, null); } public static MvcHtmlString EnumDropDownListFor&lt;TModel, TEnum&gt;(this HtmlHelper&lt;TModel&gt; htmlHelper, Expression&lt;Func&lt;TModel, TEnum&gt;&gt; expression, IDictionary&lt;string, object&gt; htmlAttributes) { var items = DoSomething(); return htmlHelper.DropDownListFor(expression, items, htmlAttributes); } </code></pre> <p>When I tried to use it in my view I still got the following exception:</p> <blockquote> <p>Compilation Error</p> <p>Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. </p> <p>Compiler Error Message: CS1928: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'EnumDropDownListFor' and the best extension method overload 'LIMM.Web.HtmlHelpers.HtmlDropDownExtensions.EnumDropDownListFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>, System.Collections.Generic.IDictionary)' has some invalid arguments</p> </blockquote> <p>Obviously I'm not extending the method correctly but so google hasn't been my friend in finding a way to accomplish this. A little help will be appreciated.</p> <p>Thanks.</p> <p><strong>UPDATE</strong>: As I type the code in the view, intellisense does give me both overloads. The error happens when I run the application.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload