title: How to save view and partial view data to database in mvc entity framework 5
body: <p>This is my controller code. I have one view and inside that i have one partial view. At the end in partial view i have one submit button. When i click this button i want to save data of main view and partial view to thier respective tables.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using MvcApplication2.Models;
  using System.Data.Entity.Validation;
  
  namespace MvcApplication2.Controllers
  {
      public class HomePageController : Controller
      {
          //
          // GET: /HomePage/
          MVCDemoEntities db = new MVCDemoEntities();
          public ActionResult Submit()
          {
              List&lt;DocTypeMaster&gt; alldoclist = new List&lt;DocTypeMaster&gt;();
              using (MVCDemoEntities db = new MVCDemoEntities())
              {
                  alldoclist = db.DocTypeMasters.OrderBy(a =&gt; a.DocTypeName).ToList();
              }
              ViewBag.docid = new SelectList(alldoclist, "Id", "DocTypeName");
              return View();
  
          }
  
  
          [HttpPost]
          [ValidateAntiForgeryToken]
          public ActionResult Submit(DetailsEntry de)
          {
              List&lt;DocTypeMaster&gt; alldoclist = new List&lt;DocTypeMaster&gt;();
              using (MVCDemoEntities db = new MVCDemoEntities())
              {
                  alldoclist = db.DocTypeMasters.OrderBy(a =&gt; a.DocTypeName).ToList();
              }
  
              ViewBag.docid = new SelectList(alldoclist, "Id", "DocTypeName", de.DocumentId);
  
  
  
                         return View(de);
          }
  
  
  
          [HttpGet]
          public PartialViewResult RacersByCountryPartial(string id)
          {
              Passport ps = new Passport();
              Pan pn = new Pan();
              string id1 = id.Trim();
              if (id1 == "Passport")
                  return PartialView("~/Views/HomePage/id1.cshtml", ps);
              else
                  return PartialView("~/Views/HomePage/pancard.cshtml", pn);
  
  
          }   
          [HttpPost]
          public ActionResult RacersByCountryPartial(string id,Passport ps, Pan pn,DetailsEntry dt)
          {
  
              return View(id);
          }
      }
  
  
  }
  </code></pre>
  
  <p>this is my Mainview.</p>
  
  <pre><code>@model MvcApplication2.DetailsEntry
  
  @{
      ViewBag.Title = "Submit";
  }
  
  &lt;h2&gt;Submit&lt;/h2&gt;
  
  @using (Html.BeginForm("Submit", "HomePage", FormMethod.Post))
  {
      @Html.AntiForgeryToken()
      @Html.ValidationSummary(true)
  
      &lt;fieldset&gt;
          &lt;legend&gt;DetailsEntry&lt;/legend&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.ClientId)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.ClientId)
              @Html.ValidationMessageFor(model =&gt; model.ClientId)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.ClientName)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.ClientName)
              @Html.ValidationMessageFor(model =&gt; model.ClientName)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.EmployeeId)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.EmployeeId)
              @Html.ValidationMessageFor(model =&gt; model.EmployeeId)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.EmpCitizenId)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.EmpCitizenId)
              @Html.ValidationMessageFor(model =&gt; model.EmpCitizenId)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.EmpName)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.EmpName)
              @Html.ValidationMessageFor(model =&gt; model.EmpName)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Nationality)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.Nationality)
              @Html.ValidationMessageFor(model =&gt; model.Nationality)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.DocumentId)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
  
             @Html.DropDownListFor(Model =&gt; Model.DocumentId, @ViewBag.docid as SelectList,"Select document Type")
              @Html.ValidationMessageFor(Model=&gt;Model.DocumentId)
              &lt;/div&gt;
  
  
      &lt;/fieldset&gt;
  }
  &lt;div id="container"&gt; &lt;/div&gt;
  &lt;script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="http://code.jquery.com/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"&gt;&lt;/script&gt;
  &lt;script src="//code.jquery.com/jquery-1.11.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="scripts/jquery-1.8.2.js"&gt;&lt;/script&gt;
  &lt;script src="~/Scripts/jquery-1.7.1.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          $("#DocumentId").change(function () {
              $("#log").ajaxError(function (event, jqxhr, settings, exception) {
                  alert(exception);
              });
  
              var countrySelected = $("select option:selected").first().text();
  
              $.get('@Url.Action("RacersByCountryPartial")',
                                { id: countrySelected }, function (data) {
  
                      $("#container").html(data);
                  });
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>This is my partial view.</p>
  
  <pre><code>@model MvcApplication2.Passport
  
  &lt;script src="~/Scripts/jquery-1.8.2.min.js"&gt;&lt;/script&gt;
  &lt;script src="~/Scripts/jquery.validate.min.js"&gt;&lt;/script&gt;
  &lt;script src="~/Scripts/jquery.validate.unobtrusive.min.js"&gt;&lt;/script&gt;
  
  @using (Html.BeginForm()) {
      @Html.AntiForgeryToken()
      @Html.ValidationSummary(true)
  
      &lt;fieldset&gt;
          &lt;legend&gt;Passport&lt;/legend&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.pissueddate)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.pissueddate)
              @Html.ValidationMessageFor(model =&gt; model.pissueddate)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.pissuedlocation)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.pissuedlocation)
              @Html.ValidationMessageFor(model =&gt; model.pissuedlocation)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.pimage)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.pimage)
              @Html.ValidationMessageFor(model =&gt; model.pimage)
          &lt;/div&gt;
  
          &lt;p&gt;
              &lt;input type="submit" value="Create" /&gt;
          &lt;/p&gt;
      &lt;/fieldset&gt;
  }
  
  &lt;div&gt;
      @Html.ActionLink("Back to List", "Index")
  &lt;/div&gt;
  </code></pre>
  
  <p>There is one submit button at the end of partial view. I want to save both main view and partial view data on single button click to respective tables. Please advise me.</p>