Click here to Skip to main content
15,921,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi ,

im unable to send the login data to controller using jquery.

Please have a look on this code :


@using System.Web.Optimization

@Scripts.Render("~/Scripts/jquery")
<script type="text/javascript">

    function GetData() {
        alert("a");
    }

    function Fail() {
        alert("b");
    }

</script>



@if (!User.Identity.IsAuthenticated)
{
    using (Ajax.BeginForm("AjaxLogin","Auth", new AjaxOptions{HttpMethod="post",OnSuccess="GetData",OnFailure="Fail" , UpdateTargetId= "result"}))
    {
     
        <div class="form-group">
            <input type="text" name="usr" class="form-control" placeholder="Email">
            <input type="password" name="pass" class="form-control" placeholder="Password">
            <input type="submit" class="btn btn-success" id="BtnLogin" value="Sign In" />
            <input type="button" class="btn btn-info" name="Register" value="Register" />
            <div id="result">
            </div>
        </div>
    }

}
else
{
    <div class="form-group">
            <input type="button" class="btn btn-success" name="profile" value="Profile"/>
            <input type="button" class="btn btn-warning" name="logout" value="Log Out" />
        </div>
}


---------------
 [HttpPost]
        public JsonResult AjaxLogin(string usr, string pass)
        {
            var stat = WebSecurity.Login(usr, pass, false);
            return Json(stat);
        }



after clicking the submit button it take me to this URL

http://localhost:58633/User/Index?usr=asdf%40hotmail.com&pass=asdf
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900