title: Get Model object from View MVC
body: <p>I have this controller</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class HomeController : Controller
  {
      public ActionResult Index()
      {
          Guest guest = new Guest;
          //add some values to guest object
          return View();
      }
  
      public ActionResult MyFunc(Guest guest)
      {
          return PartialView("Partial1", guest);
      }
  }
  </code></pre>
  
  <p><br/>
  <code>Partial1.cshtml</code> is a strongly typed partial view, so is <code>Index.cshtml</code><br/>
  I need to access the same 'guest' object passed to index view in partial view.</p>
  
  <p>Here is how my <code>Index.cshtml</code> view looks like:</p>
  
  <pre class="lang-html prettyprint-override"><code>@model MyProject.Models.Guest
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;script src="~/myjquery.js"&gt;&lt;/script&gt;
  &lt;body&gt;
      &lt;p&gt; Some Text &lt;/p&gt;
      &lt;div id="mydiv" data-model="@Model"&gt;&lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>And contents of myjquery.js</p>
  
  <pre class="lang-js prettyprint-override"><code>$(document).ready(function(){
      var url = "/Home/MyFunc";
      var model = $("#mydiv").attr("data-model");
  
      $("#mydiv").load(url, model, function(response, status, xhr){
          if(status != "success"){
              $("#mydiv").html('Failed to load more content');
          }
      });
  });
  </code></pre>
  
  <p>Contents of Partial1.cshtml</p>
  
  <pre class="lang-cs prettyprint-override"><code>&lt;p&gt; Some Text from Partial &lt;/p&gt;
  </code></pre>
  
  <p>Now, i can't access 'model' object from <code>js</code>. When i run it in debugger, it shows the object to be undefined. <br/>Kindly Help.</p>
  
  <p>I'm using VS2012, Razor view engine and MVC4</p>
  
  <p><strong>EDIT:</strong>  </p>
  
  <p>Guest.cs</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class Guest
  {
      public string Fname { get; set; }
      public string Lname { get; set; }
      public int age { get; set; }
  }
  </code></pre>