@Html.DropDownList("UserTypeId",new SelectList(ViewBag.Datalist, "UserTypeId", "UserTypeName"), new { style = "width:155px;margin-right:5px;" })我想将dropdownlist中的值添加到数据库中,为什么dropdownlist在点击添加时会提示:值不能为 null。
参数名: items,而且有时是可以添加的,有时就会提示错误
参数名: items,而且有时是可以添加的,有时就会提示错误
{
UserInfoModels userInfo1 = new UserInfoModels();
UserInfoBLL userInfo = new UserInfoBLL();
List<UserTypeModels> list = userInfo.GetUserTypeInfo();
ViewBag.Datalist = list;
return View(userInfo1);
}
这是我Action中的代码,这有值
public ActionResult Create()
{
UserInfoModels userInfo1 = new UserInfoModels();
UserInfoBLL userInfo = new UserInfoBLL();
List<UserTypeModels> list = userInfo.GetUserTypeInfo();
ViewBag.Datalist = list;
return View(userInfo1);
}
查询数据并显示在dropdownlist中,
点击添加:(下面没执行,就出现dropdownlist值不能为空的错误)
[HttpPost]
public ActionResult Create(UserInfoModels user)
{
try
{
// TODO: Add insert logic here
UserInfoBLL userInfo = new UserInfoBLL();
userInfo.Update(user);
return RedirectToAction("Index");
}
catch
{
return View();
}
}