我试图在自我转移动作(传递IsValid)之后使用RedirectToAction方法。重定向很好,但我尝试传递给动作的参数始终为空。
[HttpPost]
public ActionResult UploadForm(UploadFormViewModel formVM)
{
if (!ModelState.IsValid)
{
return View(formVM);
}
return RedirectToAction("UploadConfirm", new { confirmVM = new UploadConfirmViewModel() });
}
public ActionResult UploadConfirm(UploadConfirmViewModel confirmVM)
{
return View(confirmVM);
}
这是我的路线
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"UploadConfirm",
"{controller}/{action}/{confirmVM}",
new { controller = "EnrollmentUpload", action = "UploadConfirm" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "EnrollmentUpload", action = "UploadForm", id = UrlParameter.Optional } // Parameter defaults
);
答案 0 :(得分:2)
删除return语句中的new{}
:
return RedirectToAction("UploadConfirm", new UploadConfirmViewModel());
我也没有为Routecollection添加额外路线