【发布时间】:2016-11-08 05:20:11
【问题描述】:
每次我运行程序时,db.SaveChanges() 都会出现错误!请问,谁能帮忙解决一下?
[HttpPost]
public ActionResult Create(HttpPostedFileBase picture, form _form)
{
try
{
string ImageName = Path.GetFileName(picture.FileName);
string physicalPath = Server.MapPath("~/images/" + ImageName);
picture.SaveAs(physicalPath);
form new1 = new form();
new1.Name = _form.Name;
new1.Email = _form.Email;
new1.Phone = _form.Phone;
//.......saving picture url......
new1.DataImage = physicalPath;
//Assign for remaining feilds in table in this way.
db.forms.Add(new1);
db.SaveChanges();
}
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
{
Exception raise = dbEx;
foreach (var validationErrors in dbEx.EntityValidationErrors)
{
foreach (var validationError in validationErrors.ValidationErrors)
{
string message = string.Format("{0}:{1}",
validationErrors.Entry.Entity.ToString(),
validationError.ErrorMessage);
// raise a new exception nesting
// the current instance as InnerException
raise = new InvalidOperationException(message, raise);
}
}
throw raise;
}
return View();
}
}
【问题讨论】:
-
每次我运行程序时,db.SaveChanges() 都会出现错误! ......请任何人都可以提供解决方案?
标签: c# asp.net-mvc-5