Insert multiple entity object on single view form – ASP MVC 3

Posted: April 6, 2012 in web
        // POST: /ContactSheet/Create

        [HttpPost]
        public ActionResult Create(ContactSheet contactsheet)
        {
            if (ModelState.IsValid)
            {
                NatureProblemOther tmp = new NatureProblemOther();
                tmp.OtherDesc = lib.emas() ;
                tmp.ContactSheet = contactsheet;
                tmp.NatureProblemID = 1;
                db.NatureProblemOthers.AddObject(tmp);

                db.ContactSheets.AddObject(contactsheet);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }
            ViewBag.AgeID = new SelectList(db.Ages, "AgeID", "Description");
            ViewBag.CodeID = new SelectList(db.Codes, "CodeID", "Description", contactsheet.CodeID);
            ViewBag.RaceID = new SelectList(db.Races, "RaceID", "Description", contactsheet.RaceID);
            ViewBag.StudentID = new SelectList(db.Students, "StudentID", "Description", contactsheet.StudentID);
            ViewBag.Problem = db.NatureProblems.ToList();
            ViewBag.Release = db.Releases.ToList();
            ViewBag.Suicide = db.SuicideLists.ToList();

            return View(contactsheet);
        }


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s