-1
在我的ASP.Net MVC3剃刀的项目,我必须实现客户registration.When保存数据,返回该枚举产生在EF ASP.Net MVC3没有结果错误剃刀
“枚举没有结果”的错误
。这个错误是什么意思?以及如何解决这个问题?
控制器代码
[HttpPost]
public ActionResult CustomerRegistration(CustomerViewModel cusmodel)
{
StringBuilder sb = new StringBuilder();
if (cusmodel.CarrerPlanning)
sb.Append("Career Planning");
if (cusmodel.Personal)
sb.Append("Personal");
if (cusmodel.Relationship)
sb.Append("Parenting");
if (cusmodel.ActivityPlan)
sb.Append("Activity Plan for Childern");
if (cusmodel.Stress)
sb.Append("Stress Management");
cusmodel.Purpose = sb.ToString();
try
{
var errors = ModelState.Values.SelectMany(v => v.Errors);
if (ModelState.IsValid)
{
cus.CusModelData.Add(cusmodel);
cus.SaveChanges();
return RedirectToAction("ShowSuccess", "Home");
}
return View();
}
catch (Exception ex)
{
return View(ex.Message.ToString());
}
}
客户视图模型
public class CustomerViewModel
{
[Key]
public int CusId { get; set; }
[Required(ErrorMessage="First Name is required")]
public string Name { get; set; }
[Required(ErrorMessage="Age is required")]
[Range(0, int.MaxValue, ErrorMessage = "Please enter valid Age ")]
public int age { get; set; }
[Required(ErrorMessage = "Gender is required")]
public string Gender { get; set; }
public string FathName { get; set; }
public string MothName { get; set; }
public string OrgSchooName { get; set; }
public string Address { get; set; }
public string city { get; set; }
public string State { get; set; }
public string PIN { get; set; }
public string tele { get; set; }
public string Mob { get; set; }
public string Email { get; set; }
public string Web { get; set; }
public string Purpose { get; set; }
public string brief { get; set; }
public int Id { get; set; }
public bool IsChecked { get; set; }
public bool CarrerPlanning { get; set; }
public bool Personal { get; set; }
public bool Relationship { get; set; }
public bool Parenting { get; set; }
public bool ActivityPlan { get; set; }
public bool Stress { get; set; }
public DateTime RegistrationDate { get; set; }
//public IList<CustomerViewModel> CheckBoxItems { get; set; }
//public IEnumerable<string> CheckBoxItemsValue { get; set; }
}
}
在哪一行发生这种情况?我猜'var errors = ModelState.Values.SelectMany(v => v.Errors);'? –
@HenkMollema cus.SaveChanges(); – Nidheesh