Populating ASP.NET MVC DropDownList

前端 未结 7 1170
孤街浪徒
孤街浪徒 2020-12-08 00:42

OK, I\'ve been Googling for hours and trying everything and can\'t get anything to work. I am learning MVC using Sharp Architecture and have generated some basic forms for c

7条回答
  •  被撕碎了的回忆
    2020-12-08 00:55

    I did it this way. Works well.

    Controller

    IFarmModelInterface service2 = new FarmModelRepository();
    ViewData["Farms"] = new SelectList(service2.GetFarmNames(), "id", "FarmName", "XenApp");
    

    View

    <%: Html.DropDownListFor(m => m.Farm, (ViewData["Farms"] as SelectList)) %>
    

提交回复
热议问题