I have the following ADO Model
Student Id,Name and Course Id,Name,Student_ID
I have made the following view for it
@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 it is as
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 it gives the following Error
Server Error in '/' Application.
No parameterless constructor defined for this object.