I would like to know how to pass a string parameter using RedirectToAction().
Let's say I have this route:
routes.MapRoute(
"MyRoute",
"SomeController/SomeAction/{id}/{MyString}",
new { controller = "SomeController", action = "SomeAction", id = 0, MyString = UrlParameter.Optional }
);
And in SomeController, I have an action doing a redirection as follows:
return RedirectToAction( "SomeAction", new { id = 23, MyString = someString } );
I tried this redirection with someString = "!@#$%?&* 1" and it always fails, no matter if I encode the string. I tried encoding it with HttpUtility.UrlEncode(someString), HttpUtility.UrlPathEncode(someString), and with Uri.EscapeUriString(someString) to no avail.
So I resorted to us TempData to pass someString, but still, I would be curious to know how to make the code above work, just to satisfy my curiosity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With