Mayur Dhavle

Mayur Dhavle

  • NA
  • 119
  • 24k

MVC Exception Handling

Feb 24 2014 11:51 PM
Scenario : 
I have two controllers say Home Controller and Security Controller. My Home Controller View..Index is having Login Control {TextBoxex and Button}; Now My code in Index View of Home Controller is :

@using (Html.BeginForm("CheckLogin", "Security", FormMethod.Post))

And the code in Security Controller is :

/* Security Controller */

[HttpPost]
public ActionResult CheckLogin(LoginModel login)
{
    if (ModelState.IsValid)
    {
        if ((login.UserName.ToUpper() == "ADMIN") && (login.Password.ToUpper() == "NIMDA"))
        {
                //Do further Redirection
        }
        else
        {
                //Here I want to return to Index View of Home Controller and get error displayed
                what i have kept in ModelState.AddModelError(""); method
        }
    }
}        

Now I want to display error message from Security controller to Index View of Home Controller with Error Message that Invalid Login or Validation Summary......


Answers (4)