本文介绍了如何在Mvc4中保存数据访问层中的值列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道如何在mv4中保存DataAccessLayer中的值列表
I don't no how to save the list of values in DataAccessLayer in mv4
public ActionResult SaveMultiple(List<EmployeeDetails> save)
{
foreach (var item in save)
{
save1(save);
}
return View();
}
public Boolean save1(List<EmployeeDetails> save)
{
con.Open();
List<EmployeeDetails> emp = new List<EmployeeDetails>();
con.Close();
return true;
}
推荐答案
[HttpPost]
public ActionResult Index(List<Contact> contactList)
{
using (ContactEntities contactEntities = new ContactEntities())
{
foreach (var contact in contactList)
{
var cnct = contactEntities.Contacts.Where(c => c.ContactID.Equals(contact.ContactID)).FirstOrDefault();
if (cnct != null)
{
cnct.ContactPerson = contact.ContactPerson;
cnct.Contactno = contact.Contactno;
cnct.EmailID = contact.EmailID;
}
}
contactEntities.SaveChanges();
}
ViewBag.Message = "Successfully Updated.";
return View(contactList);
}
希望这对您有所帮助。
Hope this will be of help to you.
这篇关于如何在Mvc4中保存数据访问层中的值列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!