在不污染 URL 的情况下将模型对象传递给 RedirectToAction? [英] Passing a model object to a RedirectToAction without polluting the URL?
本文介绍了在不污染 URL 的情况下将模型对象传递给 RedirectToAction?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我想要做的:
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(ContactModel model)
{
if (ModelState.IsValid)
{
// Send email using Model information.
return RedirectToAction("Gracias", model);
}
return View(model);
}
public ActionResult Gracias(ContactModel model)
{
return View(model);
}
所有三个操作方法都在同一个控制器中.基本上,用户在联系表单中输入了一些数据,我想使用他们在 Model 对象中的名字将他们重定向到感谢页面.
All three action methods are in the same controller. Basically, a user type up some data in the contact form and I want to redirect them to a thank you page using their name in the Model object.
正如代码一样,它可以工作,但 URL 与 GET 变量一起传递.不理想.
As the code is, it works, but the URL passed along with GET variables. Not ideal.
http://localhost:7807/Contacto/Gracias?Nombre=Sergio&Apellidos=Tapia&Correo=opiasdf&Telefono=oinqwef&Direccion=oinqef&Pais=oinqwef&Mensaje=oinqwef
有什么建议吗?
推荐答案
听起来像是 临时数据!
[HttpPost]
public ActionResult Index(ContactModel model)
{
if (ModelState.IsValid)
{
// Send email using Model information.
TempData["model"] = model;
return RedirectToAction("Gracias");
}
return View(model);
}
public ActionResult Gracias()
{
ContactModel model = (ContactModel)TempData["model"];
return View(model);
}
这篇关于在不污染 URL 的情况下将模型对象传递给 RedirectToAction?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文