@Html.DropDownListFor error
I am having a function that returns
> IEnumerable<SelectListItem>
public IEnumerable<SelectListItem> ListItems
{
using
@Html.DropDownListFor( m=>Model.listItems) I am having the error message
Error 1 No ove开发者_运维知识库rload for method 'DropDownListFor' takes 1 arguments
However, it works fine with @Html.DropDownList("listItems", Model.listItems)
Why am I having the error message with @Html.DropDownListFor?
There is no overloads that satisfy those parameters. In other words, there's no method for Html.DropDownListFor() that accepts just a SelectListItem.
http://msdn.microsoft.com/en-us/library/system.web.mvc.html.selectextensions.dropdownlistfor.aspx
Try something like this:
public class YourViewModel
{
public SelectList YourSelectList { get; set; }
public string SelectedItem { get; set; }
}
Then in your view:
@Html.DropDownListFor(c=>c.SelectedItem, Model.YourSelectList)
When your form is posted, SelectedItem will hold whichever item was selected in the dropdown list.
精彩评论