我有以下不同工件的代码,
实体
public class ChooseFirst
{
public int ChooseFirstId { get; set; }
public string ChooseFirstName { get; set; }
}
查看模型
public class SelectViewModel
{
public IEnumerable<SelectListItem> ListChooseFirst { get; set; }
}
控制器/获取操作
//
// GET: /MenuOne/
public ActionResult MenuOne()
{
var selectViewModel = new SelectViewModel
{
ListChooseFirst = ChooseFirstList()
};
return View(selectViewModel);
}
private IEnumerable<SelectListItem> ChooseFirstList()
{
//here data comes from database
List<ChooseFirst> list = _getFComboService.GetFComboList();
List<SelectListItem> items = new List<SelectListItem>();
foreach (ChooseFirst chooseFirst in list)
{
SelectListItem item = new SelectListItem();
item.Text = chooseFirst.ChooseFirstName;
item.Value = chooseFirst.ChooseFirstId.ToString();
items.Add(item);
}
return items;
}
HTML 视图
@Html.DropDownList("FCombo", Model.ListChooseFirst, "--Select One--")
现在问题当我发布我的表单时,“selectViewModel”的值为NULL,是否需要建模活页夹,请建议并帮助我如何为此创建模型活页夹?
//
// POST: /MenuOne/
[HttpPost]
public ActionResult MenuOne(SelectViewModel selectViewModel)
{
return View();
}