我在多个父级动作中都放置了相同的子级动作,假设有以下两个父级视图:
@model Parent1Model
@{
ViewBag.Title = "Parent1";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@Html.Action("Child","MainControler")
第二个父级元素:
@model Parent2Model
@{
ViewBag.Title = "Parent2";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@Html.Action("Child","MainControler")
所有操作都放在同一个控制器中。
public ActionResult parent1() //GET
{
Parent1Model model = new Parent1Model()
return View(model );
}
public ActionResult parent2() //GET
{
Parent2Model model = new Parent2Model()
return View(model );
}
public ActionResult Child() //GET
{
ChildModel model = new ChildModel()
return View(model );
}
[HttpPost]
public ActionResult Child(ChildModel model) //POST
{
DoThingsWithResult(model)
// The next line should return the get of the parent action
return RedirectToParent() // This does not exist...
}
现在,我该如何告诉孩子调用他的正确父亲的 GET
方法?作为许多父母中的孩子,他怎么知道这一次是哪个父母调用了它?
我在谷歌上和“可能已经有答案的问题”中都找不到任何东西。