我有一个表单视图,它将表单数据提交到控制器上的post操作,然后重定向到另一个使用逻辑显示成功或失败的视图,但新视图只显示模型属性的空白值。这是后期行动:
[HttpPost]
public ActionResult ContactUs(TTT.Models.ContactUsModel model)
{
logger.Info(model.URL + "Contact Us Form submitted");
var userkey = model.ValidationKey;
var sessionkey = Session["ContactUsKey"];
var lastsubmission = Session["ContactUsTime"];
model.Response = "success";
//first check if honeypot was populated via a bot and if so send it to the success page without doing anything
if (model.WorkAddress != "")
{
logger.Info("honeypot triggered");
return View("ContactUsResponse", model);
}
我会遗漏控制器的其余部分,但是
以下是它重定向到的视图:
@using TTT.Models
@using Sitecore.Mvc
@model ContactUsModel
<h1>@Model.Title</h1>
<div>@Model.Body</div>
<div>
@if (@Model.Response == "fail")
{
@Model.Failure;
} else
{
@Model.Success;
}
</div>
不要返回新视图,而是调用RedirectToAction
并从该控制器返回新视图。
[HttpPost]
public ActionResult ContactUs(TTT.Models.ContactUsModel model)
{
//--- Code omitted for brevity
if (model.WorkAddress != "")
{
logger.Info("honeypot triggered");
return RedirectToAction("ContactUsResponse", new { response = model });
}
}
public ActionResult ContactUsResponse(TTT.Models.ContactUsModel response)
{
return View(model)
}