ASP.NET MVC - Html.BeginForm()。我可以发回不同的路由并保留现有的查询字符串值吗?
我有一个具有不同路线的仅后期操作。在我的表单中,我需要发布到它,但也保留我当前拥有的查询字符串值。
初始响应: /my/first/path/?val1=hello
需要发布到: /my/other/path/?val1=hello
看来当我指定路线时,它当然只返回路线而不附加我的原始页面的查询字符串值(出于明显的原因)。
是否可以将查询字符串值干净地附加到表单标记的操作属性中?谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不完全是你要问的,但我很高兴这样做:
html.BeginForm(
c => c.SomeAction(model.SomeValue, model.OtherValue, anyDefaultValueIWant)
)
使用隐藏字段代替。我不明白为什么你特别需要它出现在查询字符串中。
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.
您尝试同时进行 POST 和 GET。如果您希望正常工作,则需要输入
val1
作为隐藏值。 POST 请求没有查询字符串。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.您无法发布和保留查询字符串值。
如果您在发布时需要保留查询字符串值,我建议将它们填充到表单中的隐藏字段中。
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.