我有一个函数返回
> IEnumerable<SelectListItem>
public IEnumerable<SelectListItem> ListItems
{使用
@Html.DropDownListFor( m=>Model.listItems) I am having the error message 错误1方法'DropDownListFor‘没有重载,使用1个参数(
)
但是,它在@Html.DropDownList("listItems", Model.listItems)中运行得很好。
为什么我在@Html.DropDownListFor中有错误消息?
发布于 2011-01-26 06:54:02
没有满足这些参数的过载。换句话说,Html.DropDownListFor()没有只接受SelectListItem的方法。
http://msdn.microsoft.com/en-us/library/system.web.mvc.html.selectextensions.dropdownlistfor.aspx
试着做这样的事情:
public class YourViewModel
{
public SelectList YourSelectList { get; set; }
public string SelectedItem { get; set; }
}那么在你看来:
@Html.DropDownListFor(c=>c.SelectedItem, Model.YourSelectList)当您的表单发布时,SelectedItem将保存下拉列表中选择的任何项。
https://stackoverflow.com/questions/4801970
复制相似问题