0

これに似たドロップダウンメニューのモデルがあります。そのためのコントローラーを作成しようとしています。

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

私が間違っていることを教えていただけますか?

4

1 に答える 1

1

問題は@model List<ProjectName.Models.MyData> 単にそれをに変更することです

@model Projects.Models.MyData

乾杯!

于 2012-11-25T14:57:09.627 に答える