I\'m building my first MVC application after years of doing webforms, and for some reason I am not able to make this work:
@Html.DropDownList(\"PriorityID\"
Try below code:
@Html.DropDownList("ProductTypeID",null,"",new { @class = "form-control"})
As the signature from the error message implies, the second argument must be an IEnumerable, more specifically, an IEnumerable of SelectListItem. It is the list of choices. You can use the SelectList type, which is a IEnumerable of SelectListItem. For a list with no choices:
@Html.DropDownList("PriorityID", new List<SelectListItem>(), new {@class="textbox"} )
For a list with a few choices:
@Html.DropDownList(
"PriorityID",
new List<SelectListItem>
{
new SelectListItem { Text = "High", Value = 1 },
new SelectListItem { Text = "Low", Value = 0 },
},
new {@class="textbox"})
Maybe this tutorial can be of help: How to create a DropDownList with ASP.NET MVC
If you are add more than argument ya dropdownlist in Asp.Net MVC. When you Edit record or pass value in view bag.
Use this it will be work:-
@Html.DropDownList("CurrencyID",null,String.Empty, new { @class = "form-control-mandatory" })
Try this:
@Html.DropDownList(
"country",
new[] {
new SelectListItem() { Value = "IN", Text = "India" },
new SelectListItem() { Value = "US", Text = "United States" }
},
"Country",
new { @class = "form-control",@selected = Model.Country}
)