MVC3下拉菜单控制器

时间:2012-11-25 13:45:18

标签: asp.net-mvc-3 drop-down-menu controller

我有一个类似于this one的下拉菜单的模型。我正在尝试为它创建一个控制器。

public ActionResult Index()
    {
        ViewBag.Message = "Welcome to ASP.NET MVC!";
        return View(new MyData());
    }

我像这样创建我的视图

@Html.DropDownListFor(m => m.State,
new SelectList(Model.StateList, "Value", "Text"))

但是我收到上面这行的错误:

Compiler Error Message: CS1061: 'System.Collections.Generic.List<Projects.Models.MyData>' does not contain a definition for 'StateList' and no extension method 'StateList' accepting a first argument of type 'System.Collections.Generic.List<Projects.Models.MyData>' could be found (are you missing a using directive or an assembly reference?)

你能告诉我我做错了吗?

1 个答案:

答案 0 :(得分:1)

问题是@model List<ProjectName.Models.MyData> 只需将其更改为

即可
@model Projects.Models.MyData

喝彩!