I created a Login Page that redirects to the required page after validation. However, when it redirects, the previous Login page view appears instead of the expected view.
Below is the JavaScript code I am using:
function abc() {
var email = document.forms["MyForm"]["Email"].value;
var password = document.forms["MyForm"]["Password"].value;
if (email.length == 0 || password.length == 0) {
alert("Email and Password Field Required");
return false;
}
else {
$.ajax({
url: $("#MyForm").attr('action'),
type: $("#MyForm").attr('method'),
data: $("#MyForm").serialize(),
success: function (data) {
alert("Invalid Email or Password");
}
});
}
}
</script>
And here is the controller [HttpPost]:
public ActionResult UserLogin(Models.UserModel selectedDocuments)
{
if (ModelState.IsValid)
{
long AdminID = IsValid(selectedDocuments.Email, selectedDocuments.Password);
if (AdminID != 0)
{
FormsAuthentication.SetAuthCookie(selectedDocuments.Email, false);
if (RoleID == 1)
{
Session["SystemAdmin"] = true;
Session["AdminID"] = AdminID;
return RedirectToAction("ClubInfo", "Admin");
}
// Additional role checks and redirects...
}
else
{
ModelState.AddModelError("", "Login Data Is Incorrect.");
}
}
return Json(new { selectedDocuments = "Whatever you want to send" }, JsonRequestBehavior.AllowGet);
}
I need help in successfully implementing this. Can somebody please assist me?