我是ASP.NET MVC的新手,正在尝试学习如何通过验证提交表单。我的创建视图运行良好,它列出了带有下拉列表的字段,但是当我提交时,我收到此错误System.ArgumentNullException: Value cannot be null.。我已经阅读了几个小时,无法正常工作。需要帮忙...!
这是我公司的课程:
[Table("tblCompany")]
public class Company
{
public int CompanyID { get; set; }
[Required]
public string Name { get; set; }
[Required]
[DisplayName("Profile")]
public string Type2 { get; set; }
public string Industry { get; set; }
}
HomeController中的动作:
public ActionResult CreateCompany()
{
// Assume these two lists are working fine. The form Dropdownlist do list the options form these lists.
ViewBag.CompanyType = GenericMethods.GetGenericPicks2("CompanyType2").OrderBy(e => e.Name);
ViewBag.CompanyIndustry = GenericMethods.GetGenericPicks2("CompanyIndustry").OrderBy(e => e.Name);
return View();
}
[HttpPost]
public ActionResult CreateCompany(Company comp)
{
if (ModelState.IsValid)
{
Response.Write("Saving to DB");
// code to save to database, redirect to other page
return View(comp);
}
else
{
return View(comp);
}
}
最后,这是创建视图。该视图工作正常,显示带有选项的下拉列表...,但是当我单击“提交”时,收到了上述错误。
泛舟湖上清波郎朗
相关分类