Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add querystring values with RedirectToAction method?

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?

like image 702
mrblah Avatar asked Jul 01 '09 03:07

mrblah


People also ask

Can we use QueryString with post method?

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.

Can we pass model in RedirectToAction?

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.

What is request QueryString ()?

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).


1 Answers

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".

like image 119
Talljoe Avatar answered Oct 07 '22 00:10

Talljoe