tags:

views:

501

answers:

1

Hi

in asp.net-mvc, I am using RedirectToAction("myActionName");

I want to pass some values via the querystring, how do I do that?

+6  A: 

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

Talljoe
Agree, but action parameter with name "value1" could be present. Why not?
Alexander Prokofyev
I think the answer meant "assuming there's no route parameter named 'value1'". Otherwise the value would go into the route parameter's place in the generated URL, e.g. {controller}/{action}/{value1} would become /controller/myActionName/queryStringValue1 rather than /controller/myActionName?value1=queryStringValue1.
Levi
Levi is correct. I've fixed the answer to clarify what I meant.
Talljoe