开发者

ASP.NET MVC - Html.BeginForm(). Can I post back to a different route and keep existing querystring values?

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 m开发者_JS百科y the action attribute of the form tag? Thanks.


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜