2012-11-25 55 views
0

我有一個類似於this one的下拉菜單。我正在嘗試爲它創建一個控制器。MVC3下拉菜單控制器

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?) 

能否請你告訴我什麼,我做錯了?

+0

你如何定義MyData? –

+0

MyData與鏈接提供的鏈接非常相​​似 – jpo

+0

您如何在視圖中聲明模型? –

回答

1

問題@model List<ProjectName.Models.MyData> 只是將其更改爲

@model Projects.Models.MyData 

喝彩!