4

I am using the following code in my MVC application to login a user. If I get back "1", I redirect user to the dashboard view else login is unsuccessful.

  $.post($("form").attr("action"),
                    $("form").serialize(),
                    function (data) {
                        if (data == "1")
                            window.location.href = '/dashboard';
                        else
                            $("#result").html('bad username or password');
                    });

Is there a better way to do this via the MVC framework such that upon submission of the form, user can be redirected or not based upon login success/failure?

Thanks is advance for all replies.

1 Answer 1

1

Is there a need to do this via Ajax? If not then you just do a normal post back to your Controller that handles the post and does a RedirectToAction if successful and returns the View with errors if not.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.