c# - Login failed in ASP MVC -


i want redirect user page when logged. try solution actual page loading , not redirecting other page.

the address bar conatin new # @ end.

this code in controller :

[httppost]     public actionresult login(formcollection fc)     {         int res = dblayer.admin_login(fc["email"], fc["password"]);         if (res == 1)         {             return view("~/views/client/edit.cshtml");         }         else {             return view("~/views/client/create.cshtml");         }         return view();       } 

and have wrote in view :

<div class="login" id="login">      <div class="main-w3l">         <div class="w3layouts-main" style="background-image:url('/template/web/images/bg3.jpg'); margin-top:50px;">             <h2>login now</h2>               @using (html.beginform("login", "home", new { returnurl = viewbag.returnurl }, formmethod.post, new { @class = "form-horizontal", role = "form" }))         {                  @html.antiforgerytoken()                 @html.validationsummary(true)             }               <form action="#" method="post">                 <input value="e-mail" name="email" type="email" required="" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'e-mail';}" />                 <input value="password" name="password" type="password" required="" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'password';}" />                 <span><input type="checkbox" />remember me</span>                 <h6><a href="#">forgot password?</a></h6>                 <div class="clear"></div>                 <input type="submit" value="login" name="login">             </form>             <p>don't have account ?<a href="#" onclick="@("window.location.href='" + @url.action("create", "client") + "'") ;">register now</a></p>         </div>     </div> 

and db.cs :

 public int admin_login(string email, string password)     {          using (sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["deliverycon"].connectionstring)) {          int res = 0;         sqlcommand com = new sqlcommand("sp_login", con);         com.commandtype = commandtype.storedprocedure;         com.parameters.addwithvalue("@email", email);         com.parameters.addwithvalue("@password", password);         sqlparameter oblogin = new sqlparameter();         oblogin.parametername = "@isvalid";         oblogin.sqldbtype = sqldbtype.bit;         oblogin.direction = parameterdirection.output;         com.parameters.add(oblogin);         con.open();         com.executenonquery();         res = convert.toint32(oblogin.value);         return res;         }     } 

the problem persist when ve tried test using javascfript :

 [httppost]     public actionresult login(formcollection fc)     {         int res = dblayer.admin_login(fc["email"], fc["password"]);         if (res == 1)         {             tempdata["msg"] = " login successful !";          }         else {             tempdata["msg"] = " email or password wrong !";          }         return view();}    @{     if (tempdata["msg"] != null)     {         <script type="text/javascript">             alert('@tempdata["msg"]');         </script>     } } 

instead of returning view(); try doing

return redirecttoaction("client","edit",new { id= id}); 

this assumes have client controller edit action requires id parameter do.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -