views:

61

answers:

3

I have a post-only action that has a different route. In my form, I need to post to it, but also keep the querystring values I currently have.

Initial response: /my/first/path/?val1=hello

Needs to post to: /my/other/path/?val1=hello

It seems when I specify a route, it of course only returns the route and doesn't append the querystring values of my original page (for obvious reasons).

Is it possible to cleanly append querystring values to my the action attribute of the form tag? Thanks.

A: 

You're trying to POST and GET at the same time. If you want that you work, you'll need to input val1 as a hidden value. POST requests don't have query strings.

<input type="hidden" name="val1" value="hello"/>
Jarrett Meyer
It is possible to send post and get values. I'm able to craft a custom action value that contains querystrings and they're being accepted just fine. The resulting page is responsible for handling grabbing post and/or get variables.
Ryan Peters
A: 

You can't post and retain querystring values.
If you need to retain the querystring values when you post I would suggest populating them in hidden fields within your form.

Andy Rose
A: 

Not exactly what you are asking, but I was very happy by doing:

html.BeginForm( c => c.SomeAction(model.SomeValue, model.OtherValue, anyDefaultValueIWant) )

That uses hidden fields instead. I don't see why you specifically need it to be in the query string.

eglasius