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.
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.
精彩评论