我有这个联系表单,我想在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