title: ASP.NET MVC3: Interaction between Partial View and Main View
body: <p>I have a partial view for contact. Currently the index view shows this partial view for contact details. There is a  save button inside the partial view to save the edited data. There is a validation for age while saving the edited data. This much is working fine.</p>
  
  <p>Whenever user edit age and save it, I need to show the corresponding horoscope prediction on the main view. How do we achieve it?</p>
  
  <p><img src="https://i.stack.imgur.com/ZlISF.jpg" alt="enter image description here"></p>
  
  <pre><code>public class ContactEntity
  {
      public int ContactID { get; set; }
      public string ContactName { get; set; }
  
      [Range(18, 50, ErrorMessage = "Must be between 18 and 50")]
      public int ContactAge { get; set; }
  }
  
  public class AgeHoroscope
  {
      public int Age { get; set; }
      public string HoroscopePrediction { get; set; }
  }
  </code></pre>
  
  <p>//Home Controller</p>
  
  <pre><code>namespace MYContactEditPartialViewTEST.Controllers
  {
  public class HomeController : Controller
  {
  
      List&lt;AgeHoroscope&gt; horoList = new List&lt;AgeHoroscope&gt;()
      {
          new AgeHoroscope{Age=16,HoroscopePrediction="You are confused"},
          new AgeHoroscope{Age=26,HoroscopePrediction="You are very brilliant"},
          new AgeHoroscope{Age=27,HoroscopePrediction="You are practical"}
      };
  
      public ActionResult Index()
      {
          AgeHoroscope selectedHoro = horoList[1];
          return View(selectedHoro);
      }
  
    }
   }
  </code></pre>
  
  <p>//Contact Controller</p>
  
  <pre><code>namespace MYContactEditPartialViewTEST.Controllers
  {
  public class ContactController : Controller
  {
  
      public PartialViewResult MyContactDetailEdit()
      {
          Thread.Sleep(500);
          return PartialView(GetContact());
      }
  
  
      [HttpPost]
      public PartialViewResult MyContactDetailEdit(string conatcclick)
      {
          //Save to database
          Thread.Sleep(500);
          return PartialView(GetContact());
      }
  
  
      private ContactEntity GetContact()
      {
          ContactEntity contactEntity = new ContactEntity();
          contactEntity.ContactID = 1;
          contactEntity.ContactName = "Lijo";
          contactEntity.ContactAge = 26;
          return contactEntity;
      }
  
   }
  }
  </code></pre>
  
  <p>//Index.cshtml</p>
  
  <pre><code>@model  MYContactEditPartialViewTEST.AgeHoroscope
  @{
   ViewBag.Title = "Index";
  }
  
  &lt;script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"&gt;       &lt;/script&gt;
  
  
  
  &lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;h2&gt;
      Index&lt;/h2&gt;
  
  &lt;div&gt;
  &lt;a&gt;Your age is &lt;b&gt;@Html.DisplayFor(x =&gt; x.Age) &lt;/b&gt;and the prediction is &lt;b&gt;" @Html.DisplayFor(x =&gt; x.HoroscopePrediction)
      " &lt;/b&gt;&lt;/a&gt;
  &lt;br /&gt;
   &lt;/div&gt;
  &lt;div style="border: 3px solid Teal"&gt;
  @Html.Action("MyContactDetailEdit", "contact")
  &lt;/div&gt;
  </code></pre>
  
  <p>// MyContactDetailEdit.cshtml</p>
  
  <pre><code>@model  MYContactEditPartialViewTEST.ContactEntity
  
  
  @using (Html.BeginForm())
  {
  @Html.ValidationSummary(true)
  
  &lt;h3&gt;MyContactDetailEdit PARTIAL&lt;/h3&gt;
  
  &lt;div&gt;
  @Html.HiddenFor(x =&gt; x.ContactID)
  &lt;br /&gt;
  &lt;div style="font-weight:bold"&gt; 
      Name:
      &lt;br /&gt;
  &lt;/div&gt;
  @Html.DisplayFor(x =&gt; x.ContactName)
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;div style="font-weight:bold"&gt;
      Age
      &lt;br /&gt;
  &lt;/div&gt;
  @Html.EditorFor(x =&gt; x.ContactAge)
  @Html.ValidationMessageFor(model =&gt; model.ContactAge)
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;/div&gt;
  
   &lt;input type="submit" id="saveButton" value="Save" /&gt;
  
  }
  </code></pre>
  
  <p>READING</p>
  
  <ol>
  <li><p><a href="https://stackoverflow.com/questions/2199440/asp-net-mvc-passing-multiple-parameters-to-a-view">ASP.Net MVC Passing multiple parameters to a view</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/4467712/asp-net-mvc-3-rc2-partial-views-form-handling">ASP.Net MVC 3 RC2, Partial Views Form Handling</a></p></li>
  </ol>