Search code examples
jqueryasp.net-mvcasp.net-mvc-4razorjquery-2.0

jquery submit form and query string issue


I have some values on the query string of the form page. When I submit the form using the submit button it self I can get the query string values but when I submit the form using jquery as below. I don't see the query string values anymore. Am I messing something?

      $('#PasswordResetForm').submit(function () {

         if (some conditions) {
            $('#PasswordResetForm').submit();
         }
         else {             
            return false;
         }
      });

the link is something like this:

 http://websitename/Account/PasswordReset/?username=username&token=ZnsHnVh3oIOwOR2GUaGfsA2

html code is as below:

@using (Html.BeginForm("PasswordReset","Account",FormMethod.Post,new        
                                                      {id="PasswordResetForm"}))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary("", new { id = "validation" })

    <fieldset>
        <legend ">Enter your User Name</legend>

        <br />

        <table id="MainTable" border="0">
            <tr class="MainTr">
                <td class="FirstTd">
                    @Html.Label("User Name")
                </td>
                <td class="SecondTd">

                </td>

            </tr>
            <tr class="MainTr">
                <td class="FirstTd">
                    New Password
                </td>
                <td class="SecondTd">
                    @Html.Password("newPassword")
                </td>

            </tr>
            <tr class="MainTr">
                <td class="FirstTd">
                    Confirm New Password
                </td>
                <td class="SecondTd">
                    @Html.Password("confirmNewPassword")
                </td>

            </tr>                
            <tr class="MainTr">                                        
                <td colspan="2">
                    <input type="submit" id="submitBt" value="Recover Password" />
                </td>                    
            </tr>
        </table>
    </fieldset>
}

I can't see the token on the server anymore. when I use jquery to submit the form. I'm using mvc 4 and jquery 2.0.0


Solution

  • Try This

    $(function()
    {
    
        function  ValidateData() {
                 if (some conditions) {
                    return true;
                 }
                 else {             
                    return false;
                 }
              }
    });
    

    HTML Changes

     <input type="submit" id="submitBt" value="Recover Password" onClick="return ValidateData();" />