Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My login page contains two tab.One for LogIn and another for SignUp.
In my LogInController,I created three action method as shown in below section.
C#
[HttpGet]
[ActionName("LogIn")]
public ActionResult LogIn()
{
    return View();
}

[HttpPost]
[ActionName("LogIn")]
public ActionResult LogIn(string Email, string Password)
{
    //Some code
    return RedirectToAction("LogIn", "LogIn");

}


[HttpPost]
[ActionName("SignUp")]
public ActionResult SignUp(string Email,string Password)
{
    //Some Code
    return RedirectToAction("SignUpWizard", "SignUpWizard");
}


My view call this Action Method using AJAX.My View and AJAX call look like this.

<!DOCTYPE html>
<html>
<head>
    <title>Login</title>
    <link href="~/Content/css/main.css" rel="stylesheet" />
    <link href="~/Content/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <script src="~/Scripts/knockout-2.2.0.js"></script>
    <script src="~/Scripts/knockout-2.2.0.debug.js"></script>
    <script src="~/Content/js/jquery.js"></script>
    <script src="~/ViewModel/LoginViewModel.js"></script>
</head>
<body>
    <nav class="navbar navbar-custom" role="navigation">
        <div class="container-fluid">
            <h2 class="text-center t-size-change">Login</h2>
        </div>
        <!-- /.container-fluid -->
    </nav>
    <div class="container m-t-150">
        <div class="row">
            <div class="col-md-12">
                <div class="login-tabs">
                    <!-- Nav tabs -->
                    <ul class="nav nav-tabs nav-justified nav-tabs-custom" role="tablist">
                        <li class="active"><a href="#home" role="tab" data-toggle="tab">Login</a></li>
                        <li><a href="#profile" role="tab" data-toggle="tab">Sign up for free</a></li>
                    </ul>
                    <!-- Tab panes -->
                    <div class="tab-content">
                        <div class="tab-pane active custom-tab" id="home">
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="form-group">
                                        <input type="email" placeholder="Email Address" class="form-control" name="Email" id="txtLogInEmail" required>
                                    </div>
                                    <div class="form-group">
                                        <input type="password" placeholder="Password" class="form-control" name="Password" id="txtLogInPassword" required>
                                    </div>
                                    <input type="button" value="Login to Tucan Rotas" class="btn btn-success btn-custom" id="btnLogIn" />
                                    <p class="text-center p-10"><a href="#">Forgot your password?</a></p>
                                </div>
                            </div>
                        </div>
                        <div class="tab-pane custom-tab" id="profile">
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="form-group">
                                        <input type="email" placeholder="Email Address" class="form-control" name="Email" id="txtSignUpEmail" required>
                                    </div>
                                    <div class="form-group">
                                        <input type="password" placeholder="Password" class="form-control" name="Password" id="txtSignUpPassword" required>
                                    </div>
                                    <input type="button" id="btnSignUp" class="btn btn-success btn-custom" value="Sign up for free" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="~/Content/plugins/bootstrap/js/bootstrap.min.js"></script>
    <script src="~/Content/js/tab.js" type="text/javascript"></script>
    <script>
        $(function () {
            $('#btnSignUp').click(function () {
                $.ajax({
                    url:'@Url.Action("SignUp", "LogIn")',
                    method:"POST",
                    data: { Email: $('#txtSignUpEmail').val(), password: $('#txtSignUpPassword').val() }
                });
            });
            $('#btnLogIn').click(function () {
                $.ajax({
                    url: '@Url.Action("LogIn", "LogIn")',
                    method: "POST",
                    data: { Email: $('#txtLogInEmail').val(), password: $('#txtLogInPassword').val() }
                });
            });
        });
    </script>

</body>
</html>


When I enter EmailID and password in SignUp OR LogIn and click SignUp Or LogIn button, Every Time It call LogIn() method decorate with HttpGet Attribute.However This same code working properly in different System.
Posted
Updated 26-May-15 20:04pm
v2
Comments
[no name] 27-May-15 4:47am    
Why don't u put ur code in form tag?
ArjunBhalodiya 27-May-15 5:20am    
I use Html.BeginForm as well as Ajax.BeginForm, But both causes same problem.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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