0

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

1 回答 1

2

删除new{}您的退货声明中的:

return RedirectToAction("UploadConfirm", new UploadConfirmViewModel());

我也没有向 Routecollection 添加额外的路由

于 2012-04-13T06:32:12.487 回答