Reputation: 6911
I am trying to use a RedirectToAction method after a selfposting Action (which passes IsValid). The redirect happens fine but the parameter I am attempted to pass to the action is always null.
[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);
}
And here is my routing
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
);
Upvotes: 0
Views: 1644
Reputation: 5430
Remove the new{}
in your return statement:
return RedirectToAction("UploadConfirm", new UploadConfirmViewModel());
I also did not add an extra route to the Routecollection
Upvotes: 2