I have the following ADO model
Student Id, Name and Course Id, Name, student_id
I made the following presentation for him
@model Tuple<MvcApplication4.Models.Course, MvcApplication4.Models.Student > @{ ViewBag.Title = "Create"; } <h2>Create</h2> @using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset> <legend>Course</legend> <div class="editor-label"> @Html.LabelFor(model => model.Item1.Name) </div> <div class="editor-field"> @Html.EditorFor(model => model.Item1.Name) @Html.ValidationMessageFor(model => model.Item1.Name) </div> <div class="editor-label"> @Html.LabelFor(model => model.Item1.S_ID, "Student") </div> <fieldset> <legend>Student</legend> <div class="editor-label"> @Html.LabelFor(model => model.Item2.Name) </div> <div class="editor-field"> @Html.EditorFor(model => model.Item2.Name) @Html.ValidationMessageFor(model => model.Item2.Name) </div> <div class="editor-label"> @Html.LabelFor(model => model.Item2.Class) </div> <div class="editor-field"> @Html.EditorFor(model => model.Item2.Class) @Html.ValidationMessageFor(model => model.Item2.Class) </div> <p> <input type="submit" value="Create" /> </p> </fieldset> </fieldset> }
And the controller for him is like
public ActionResult Create() { return View(); } // // POST: /Default3/Create [HttpPost] public ActionResult Create(Tuple<Student ,Course > t) { try { // TODO: Add insert logic here db.Students.AddObject(t.Item1); db.SaveChanges(); t.Item2.S_ID = t.Item1.Id; db.Courses.AddObject(t.Item2); db.SaveChanges(); return RedirectToAction("Copy"); } catch { return View(); } }
But when I click the Creat button, you get the following error
Server error in application "/".
There is no constructor without parameters for this object.
source share