2016-05-13 7 views
0

Ich arbeite mit mvc, C# und boostrap. In meiner Navbar habe ich ein DropDown um mich anzumelden. Es ist wie das Facebook Login oben rechts platziert.Drop-Down Login Mvc

<li class="dropdown"> 
    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><img class="img-responsive" src="/images/h-perfil.png" alt="imagen"> perfil <span class="caret"></span></a> <div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;"> 
     <form method="post" action="login" accept-charset="UTF-8"> 
      <input style="margin-bottom: 15px;" type="text" placeholder="Email" id="username" name="username"> 
      <input style="margin-bottom: 15px;" type="password" placeholder="Contraseña" id="password" name="password"> 
      <input class="btn btn-primary btn-block" type="submit" id="sign-in" value="Ingresar"> 
      <label style="text-align:center;margin-top:5px">Registrarme</label> 
     </form> 
    </div> 
</li> 

Ich frage mich, wie man Modelle verwendet, um die Benutzer einzuloggen. Ich habe auch einen Controller, der mein Modell verwendet. Dies ist mein Controller

public ActionResult LogIn(UserModel model) 
{ 
    if (!ModelState.IsValid) //Checks if input fields have the correct format 
    { 
     return View(model); //Returns the view with the input values so that the user doesn't have to retype again 
    } 
    if (credential valids) 
    { 
     return RedirectToAction("Index", UserModel); } 

Also in diesem Fall möchte ich Benutzer anmelden, wenn Sie auf den Buton klicken. Dank

+0

Können Sie die UserModel Klasse schreiben. Grundsätzlich sollten die Eigenschaften dieser Klasse dem name-Attribut des Eingabe-Tags entsprechen. Wenn Sie senden, wird UserModel Klasse automatisch –

+0

Hallo, danke für Ihre Antwort. dies –

+0

Das ist das Modell: public class userlogin { öffentliche string Email {get; einstellen; } public string Passwort {get; einstellen; } } So sagen Sie, dass es automatisch bevölkern wird. Aber wie kann ich die Controller-Aktion namens Login nennen, wenn man auf die Schaltfläche Anmelden klickt? danke nochmal! –

Antwort

0

Assign korrekten Wert Aktion attribute.Use "E-Mail" Wert für ID und Name für die erste Textbox

<form method="post" action="@Url.Action("LogIn", "YourControllerName")" accept-charset="UTF-8"> 
     <input style="margin-bottom: 15px;" type="text" placeholder="Email" id="Email" name="Email"> 
     <input style="margin-bottom: 15px;" type="password" placeholder="Contraseña" id="password" name="password"> 
     <input class="btn btn-primary btn-block" type="submit" id="sign-in" value="Ingresar"> 
     <label style="text-align:center;margin-top:5px">Registrarme</label> 
</form> 

Dekorieren mit Httppost Attribut:

[HttpPost] 
public ActionResult LogIn(UserModel model) 
{ 
    //code 
} 
+0

danke! es funktionierte! –