In my asp.net mvc 2 application, why are parameters passed via RedirectToAction sometimes lost?
This perplexes me. Sometimes using RedirectToAction works, sometimes it doesn't. I haven't found any rhyme or reason to it. Here's an example:
return RedirectToAction("ExportReport",
new { FieldOrder = fieldOrder });
I've also tried this variant:
return RedirectToAction("ExportReport", "SearchAndExport",
new { FieldOrder = fieldOrder });
I added the following in my global.asax.cs:
routes.MapRoute(
"ExportReport",
"{controller}.aspx/{action}/{FieldOrder}",
new { controller = "SearchAndExport", action = "ExportReport", FieldOrder = UrlParameter.Optional }
);
And lastly, the prototype for the action I'm redirecting to:
public FileContentResult ExportReport(List<String> FieldOrder)
FieldOrder's data never makes it to the redirected action. Why? I know I've done this and had it work many times as well. What gives?
EDIT 1
To make it perfectly clear, FieldOrder is a List<String>
. I am not using site areas. The redirect itself works, but the data is not passed to the method. I have verified that there is data that should be passed via debug.
Also, I'd rather not use TempData. If you have more than one action redirect to another more general action, that becomes messy. It's cleaner (IMHO) to just pass the data via the parameter.
Going over some of my old questions here...
The reason these redirect values were getting lost was that I was passing a complex object as a parameter. ASP.NET MVC 2 did not handle these. Redirects with primitive type parameters will work fine.