如何重定向到页面并传递其模型?
就像我们在 MVC 中所做的那样return View(model: MyModel);
我尝试过的:return RedirectToPage("/Notify", new { Model = notifierVM });
注意:我要返回的Page后面没有PageModel
MVC 内置了字典对象TempData。
您可以序列化您的模型,将 JSON 字符串放入 TempData,然后在重定向操作中您可以获取 JSON 字符串并将其反序列化为对象。
public ActionResult Create(Booking item)
{
TempData["data"] = JsonConvert.SerializeObject(MyModel);
return RedirectToAction("Details", new { id = 1 });
}
关于其他行动
public ActionResult Details(int id)
{
object o;
TempData.TryGetValue("data", out o);
var MyModel = JsonConvert.DeserializeObject<T>((string)o);
...
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)