我试图在自发布操作(通过 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
);