親アクション内に子アクションを埋め込み、子アクションからフォームが送信されたときにページ全体を適切にレンダリングする方法を学んでいます。
ParentAction.cshtml --------------------------------------
@model Web1.Models.ParentActionModel
@{ViewBag.Title = "ParentAction";}
<h2>Parent Action</h2>
@Html.ValidationSummary(true, "Please correct parent errors and try again.")
@using (Html.BeginForm()) {
//parent forminput stuff
<input type="submit" value="Parent Button" />
}
@Html.Action("ChildAction","Home") <!-- ChildAction is included here -->
ChildAction.cshtml(parent.cshtmlに含まれています)------------
@model Web1.Models.ChildActionModel
@{ViewBag.Title = "ChildAction";}
<h2>Child Action</h2>
@Html.ValidationSummary(true, "Please correct child errors and try again.")
@using (Html.BeginForm("ChildAction", "Home")) {
//child form input stuff
<input type="submit" value="Child Button" />
}
HomeController.cs -----------------------
public ActionResult ParentAction() {
return View();
}
[HttpPost]
public ActionResult ParentAction(ParentActionModel pmodel) {
//do model update stuff
return View(pmodel);
}
[ChildActionOnly]
public ActionResult ChildAction() {
return PartialView();
}
[HttpPost]
public ActionResult ChildAction(ChildActionModel cmodel) {
//do model update stuff
return PartialView(cmodel); // <---This is wrong, What's the correct way to do it?
}
ここで、[子ボタン]をクリックすると、子アクション(durrr!)のビューのみが表示されますが、完全なページの親+子ビューを生成するように修正するにはどうすればよいですか?それは十分に簡単な論理のように思えますが、私は何時間もそれに固執しています。