如何通过RedirectToAction传递类 [英] How to pass class via RedirectToAction
本文介绍了如何通过RedirectToAction传递类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的code:
public ActionResult Index()
{
AdminPreRegUploadModel model = new AdminPreRegUploadModel()
{
SuccessCount = successAddedCount,
FailureCount = failedAddedCount,
AddedFailure = addedFailure,
AddedSuccess = addedSuccess
};
return RedirectToAction("PreRegExceUpload", new { model = model });
}
public ActionResult PreRegExceUpload(AdminPreRegUploadModel model)
{
return View(model);
}
但模型为空时,我断点preRegExcelUpload。为什么呢?
but model is null when I breakpoint on PreRegExcelUpload. Why?
推荐答案
我会建议使用 TempData的
。见的http://rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications关于的TempData code>。
Instead of using the Session
object in Evgeny Levin's answer I would suggest to use TempData
. See http://rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications about TempData
.
您也可以通过调用收益preRegExceUpload(模型)解决这个问题$ C>你
首页
功能。
You could also fix this by calling return PreRegExceUpload(model);
instead of return RedirectToAction(..)
in you Index
function.
这篇关于如何通过RedirectToAction传递类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文