Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC Partial View not returning model on ajax postback
    primarykey
    data
    text
    <p>I have a view which has a partial view in it, which has a text box in it. The main view has a model of type person and the partial view a model of type person.other. When I do a ajax post back the other model is empty, I expected it to pick up the textbox data. This is the code;</p> <p>Classes</p> <pre><code>public class Person { public string PersonID { get; set; } public string Name { get; set; } public Other Other { get; set; } } public class Other { public string OtherName { get; set; } } </code></pre> <p>Controller</p> <pre><code>[AcceptVerbs(HttpVerbs.Get)] public ActionResult Index() { Person person = new Person(); person.Other = new Other(); person.Other.OtherName = "avbc"; return View(person); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult Test(Other other) { if (Request.IsAjaxRequest()) { return PartialView("Test"); } return null; } </code></pre> <p>View</p> <pre><code>@model PartialViewTest.Models.Person &lt;h2&gt;Index&lt;/h2&gt; &lt;div id="mydiv"&gt; @Html.Partial("Test", Model.Other) &lt;/div&gt; </code></pre> <p>PartialView</p> <pre><code>@model PartialViewTest.Models.Other &lt;h1&gt;Test&lt;/h1&gt; @using (Html.BeginForm("Test", "Home", FormMethod.Post, new { id = "testForm" })) { @Html.TextBoxFor(m =&gt; m.OtherName) &lt;input type="submit"/&gt; } </code></pre> <p>Jquery submit </p> <pre><code>$(document).ready(function () { $('#testForm').submit(function () { $.post($(this).attr("action"), $(this).serialize(), function (result) { $('#mydiv').html(result); }); ); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload