我有這個聯繫表單,我想在MVC 5.x(剃鬚刀viewengine)在兩個頁面(兩個視圖)上使用所以我已經把窗體放在稱爲_Contact的partialview中,我有閱讀的RenderAction是最好的辦法,如果你沒有在模型中的partialview所需要的數據,如果是多個獨立(從視圖中的其餘部分單獨)MVC RenderAction返回只渲染局部部分
所以我這樣稱呼它:
@{ Html.RenderAction("SendMail", "Uk");}
我的英國控制器有這兩種方法:
[HttpGet]
public PartialViewResult SendMail()
{
return PartialView("_Contact");
}
[HttpPost]
public PartialViewResult SendMail(FormCollection fc)
{
// send mail using values out of the form (sorry did not feel like building a complete model for it
ViewBag.Succeed = true;
// if smtpclient could not reach server etc. it returns false
return PartialView("_Contact");
}
它一切正常,但PartialView
只是渲染,而不是佔位符,我呼籲RenderAction
。它的工作原理都很棒,但是在帖子發佈之後,它只顯示部分視圖,而不是「父視圖」和共享佈局視圖等。我希望我明確自己。如果我需要添加更多信息,請讓我知道。
這是從我的共享視圖的BeginForm
:
using (Html.BeginForm("SendMail", "Uk", FormMethod.Post))
也許是因爲你在GET或POST的情況下返回'PartialView' – ediblecode