开发者

jQuery submit() - Append querystring to page?

开发者 https://www.devze.com 2023-01-08 02:42 出处:网络
I have a dropdown menu, which I want to use $(\'form#form\').submit(); on from a .change() event, but how would I append a query string to the submitted page?

I have a dropdown menu, which I want to use $('form#form').submit(); on from a .change() event, but how would I append a query string to the submitted page?

So the resulting page would be example.com/submitted-form/?qu开发者_开发百科erystring=something


If I understand it right, you want to set up your form like:

<form id="form" method="get" action="">
<select name="querystring">
...dropdown menu...
</select>
</form>

By submitting this form, you will be directed to the same page, appending the query string.


Assuming

 @using (Html.BeginForm("Index", "VO", FormMethod.Post, new { id = "MyForm" }))
 {

 }

or

<form action="/VO" id="MyForm" method="post"></form>

You've got to hyjack your action property

    $("#MyForm").attr("action", "/VO?Page=" + $(this).text());
    $("#MyForm").submit();

You will get your form elements plus that so very useful query string parameter.

0

精彩评论

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