【发布时间】:2015-03-29 20:06:25
【问题描述】:
我需要将 mvc 4 中的下拉列表与类文件中的字典绑定。
我的类文件是
namespace RealEstate.ViewModel
{
public class Dropdowns
{
public Dictionary<int, string> ddlCount()
{
Dictionary<Int32, string> dict = new Dictionary<int, string>();
dict.Add(0, "1");
dict.Add(1, "2");
dict.Add(2, "3");
dict.Add(3, "4");
dict.Add(4, "5");
dict.Add(5, "6");
dict.Add(6, "7");
dict.Add(7, "8");
return dict;
}
}
}
我是使用 viewbag 为控制器传递值
public ActionResult Save()
{
Dropdowns ddl = new Dropdowns();
ViewBag.ddlcount = ddl.ddlCount();
return View();
}
并像在视图中一样接收它
@Html.DropDownListFor(model => model.type, ViewBag.ddlcount as List<SelectListItem>)
我正在使用强类型视图 @model RealEstate.Models.listing
请帮帮我
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-4