Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC parent and child nested views returning models
    primarykey
    data
    text
    <p>Suppose I have a parent.cshtml view with a parentModel, and a child.cshtml view with a childModel. This child action is <code>[ChildActionOnly]</code> and is rendered in parent.cshtml: <code>@Html.Action("ChildAction")</code>.</p> <p>Now, in controller/ParentAction</p> <pre><code>public ActionResult ParentAction() {return View();} [HttpPost] public ActionResult ParentAction(ParentModel parentmodel) { if(!ModelState.IsValid) { ... ModelState.AddModelError("", "parent view has an error"); } return View(parentmodel); // pass the ball back to user } </code></pre> <p>in controller/ChildAction</p> <pre><code>[ChildActionOnly] public ActionResult ChildAction() {return View();} [HttpPost] public ActionResult ChildAction(ChildModel childmodel) { if(!ModelState.IsValid) { ... ModelState.AddModelError("", "child view has an error"); } //??? return ParentView(parentmodel, childmodel) ??? how do i do this??? } </code></pre> <p>In the child action, how do I return to the ParentView (that also renders the ChildView), and preserve the data in their models?</p> <p>EDIT:-----</p> <p>My point is how not to do that. <code>return View(childmodel);</code> from child action will not get us what we want to see, because it will only give us a 'partial' page with child view only, the parent part is missing. <code>RedirectToAction("ParentAction");</code> will give us full view again, but it will lose the models. Not sure how to handle returning models in nested views. That's where I am stuck. </p>
    singulars
    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.
 

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