开发者

asp.net mvc 2.0 Jquery form submit

开发者 https://www.devze.com 2023-01-09 17:02 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消