[RESOLVED]does not contain a definition for 'DropDownList' and the best extension method overload 'System.Web.Mvc.Html.SelectExtensions.DropDownList

How can I fix this when I get this error.

CS1928: ‘System.Web.Mvc.HtmlHelper<PagedList.IPagedList<TweddlePhoneListApplication.Models.MasterList>>’ does not contain a definition for ‘DropDownList’ and the best extension method overload ‘System.Web.Mvc.Html.SelectExtensions.DropDownList(System.Web.Mvc.HtmlHelper,
string, System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>, object)’ has some invalid arguments

@using (Html.BeginForm())
{

    <p>

        <div class="form-inline">
            Find by Last Name or First Name: @Html.TextBox("SearchString", ViewBag.CurrentFilter as String, new { style = "width:200px", @class = "form-control" })

            Location:

            @Html.DropDownList("LocationList", "All", new { @class = "required " })


            <input type="submit" value="Search" class="btn btn-default" />
        </div>
    </p>

}

Do you have 

@using Site.HTMLHelpers

?

http://forums.asp.net/t/1678594.aspx?MVC+pager+help 

You are using wrong overload, if you want to add Default option use this overload:

@Html.DropDownList(string name,IEnumerable<SelectListItem> selectList,string optionLabel,object htmlAttributes)

So how do I convert this   @Html.DropDownList("LocationList", "All", new { @class = "required " })

to this @Html.DropDownList(string name,IEnumerable<SelectListItem> selectList,string optionLabel,object htmlAttributes)

What do you intend your DropDownList to be populated with?
Nearly all of the DropDownList constructors
require you to pass in some type of collection or a SelectList of elements that will populate the DropDownList. The only one that doesn’t accept an IEnumerable of some type is the following one, which doesn’t
support htmlAttributes :

public static MvcHtmlString DropDownList(this HtmlHelper htmlHelper, string name, string optionLabel)

You could modify this slightly and pass in a single element to your DropDownList ("All") using a different overload as follows :

@Html.DropDownList("LocationList", new SelectList(new List<string>(){ "All" }), new { @class = "required " })

or just manually build the element yourself :

<select id="LocationList" name="LocationList" class='required'>
    <option value="All">All</option>
</select>

Thank you Rion

I added this and still no luck…

Html.DropDownList("LocationList", new SelectList(new List<string>(){ "All" }), new { @class = "required " })

yguyon

I added this and still no luck…

Html.DropDownList("LocationList", new SelectList(new List<string>(){ "All" }), new { @class = "required " })

This should render an element that looks like the following :

<select name="LocationList" class="required" id="LocationList">
    <option>All</option>
</select>

What in particular are you hoping for it to render?

Leave a Reply