In asp.net mvc, I am using this code:
RedirectToAction("myActionName");
I want to pass some values via the querystring, how do I do that?
A POST request can include a query string, however normally it doesn't - a standard HTML form with a POST action will not normally include a query string for example.
By including a NuGet package called MvcContrib you can easily pass model or form data through a simple RedirectToAction function call inside of your controllers. The data will then be handled in the other view and be strongly typed to the model you are passing through the redirect.
The value of Request. QueryString(parameter) is an array of all of the values of parameter that occur in QUERY_STRING. You can determine the number of values of a parameter by calling Request. QueryString(parameter).
Any values that are passed that aren't part of the route will be used as querystring parameters:
return this.RedirectToAction ("myActionName", new { value1 = "queryStringValue1" });
Would return:
/controller/myActionName?value1=queryStringValue1
Assuming there's no route parameter named "value1".
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