asp.net mvc - How to display wrong username password on login form ? -
i developing mvc application. have designed login form.
when user enters proper username , password then, redirect next page, when user put wrong username or password want display message on login form, how it.
this code of method in controller...
[httppost] public actionresult loginuser(formcollection oformcollection) { string username = oformcollection["username"]; string password = oformcollection["password"]; bool isaccountperson = false; var validemployee = (from e in db.employees e.username == username && e.password == password select e).tolist(); if (validemployee.count() == 1) { foreach (var v in validemployee) { oemployee = v; session["loggedemployee"] = oemployee; session["loggedempid"] = oemployee.id; if (oemployee.designationtype == "account") { isaccountperson = true; } else { isaccountperson = false; } } if(isaccountperson) return redirecttoaction("paymentadvicelistforaccounts", "account"); else return redirecttoaction("index", "paymentadvice"); } else return partialview("index"); }
and view code....
<!doctype html> <html> <head> <meta charset="utf-8" /> <link href="@url.content("~/content/bootstrap.css")" rel="stylesheet" type="text/css" /> <title></title> </head> @using (html.beginform("loginuser","login",formmethod.post)) { @*<div style="margin:15% 20% 20% 30%; width:35%;min-height:25%;border:1px #acacac solid;">*@ <div class="container-fluid" style="padding-left:0px; margin-top:165px; margin-left:140px;"> <div class ="span3"> <label style="font-size:15px; color:#666666; margin-top:5px;">username</label> </div> <div class ="span6"> <input type="text" id="username" name="username" style="height:20px; width:100%;" /> </div> <div class ="span3"> <label style="font-size:15px;color:#666666; margin-top:5px; ">password</label> </div> <div class ="span6"> <input type="password" id="password" name="password" style="height:20px; width:100%;"/> </div> <div class="span6" style="padding-left:15px;"> <input type="submit" name="submit" value="login" class="btn btn-primary" style="margin-right:10px; height:30px; font-size:14px; width:55px;" /> <input type="button" name="login" value="cancel" class="btn btn-primary" style="margin-right:20px; height:30px; font-size:14px; width:55px; padding-left:5px; padding-right:5px;" /> </div> </div> </div> </div> </div> } </body> </html>
create new model or use tempdata.
here example using tempdata.
http://www.devcurry.com/2012/05/what-is-aspnet-mvc-tempdata.html
Comments
Post a Comment