Asp.net mvc 2.0 jquery form submit

I use the following code in my MVC application to log in to the user system. If I return "1", I redirect the user to the control panel view, otherwise the login was 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 using the MVC environment so that when a form is submitted, the user can be redirected or not based on login success / failure?

Thanks for all the answers.

+4
source share
1 answer

Does this need to be done through Ajax? If not, you simply make a regular post back to your controller, which processes the message, and does RedirectToAction if successful and returns a View with errors if not.

+1
source

All Articles