【问题标题】:@Html.DropDownListFor error@Html.DropDownListFor 错误
【发布时间】:2011-01-26 06:45:01
【问题描述】:

我有一个返回函数

> 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 的错误消息?

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-3


    【解决方案1】:

    没有满足这些参数的重载。换句话说,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 将保存下拉列表中选择的任何项目。

    【讨论】:

      猜你喜欢
      • 2012-02-19
      • 2014-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      相关资源
      最近更新 更多