如何在Mvc4中保存数据访问层中的值列表 [英] How Can I Save A List Of Values In Data Access Layer In Mvc4

查看:49
本文介绍了如何在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;

       }

推荐答案

请查看以下使用的Controller Action方法示例示例使用Entity Framework批量更新数据: -



Please have a look into the below sample example of a Controller Action method which is used to bulk update data using Entity Framework:-

[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中保存数据访问层中的值列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆