Skip to content

Why modelstate.isvalid value getting false

Pooja Chowdhury

Asked Feb 9, 2017, 9:50 PM EST1 answer
Share
LinkedInX
Python
[HttpPost]             public ActionResult Index(MemberInfo MB)         {             if (ModelState.IsValid)             {                 DBAccessLayer.DBdata objDB = new DBAccessLayer.DBdata();                 if (objDB.checkUser(MB.UserName, MB.Password)) // Calls the Login class checkUser() for existence of the user in the database.                 {                     return View("Show", MB); // Return the "Show.cshtml" view if user is valid                 }                 else                 {                     ViewBag.Message = "Invalid Username or Password";                     return View(); //return the same view with message "Invalid Username or Password"                 }             }             else             {                 return View();             }         }

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    C#
    [HttpPost]             public ActionResult Index(MemberInfo MB)      
       {             if (ModelState.IsValid)            
     {                 DBAccessLayer.DBdata objDB = new DBAccessLayer.DBdata(); 
                    if (objDB.checkUser(MB.UserName, MB.Password)) // Calls the Login class checkUser() for existence of the user in the database.        
             {                     return View("Show", MB); // Return the "Show.cshtml" view if user is valid                 }   
                  else                
     {                     ViewBag.Message = "Invalid Username or Password"; 
                        return View(); //return the same view with message "Invalid Username or Password"      
               }             }             else             {                 return View();             }         }
    0