我正在使用mvc、c#和boostrap。在我的导航栏中,我有一个要登录的下拉列表。它的位置就像facebook登录一样,位于右上角。
<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>
我想知道如何使用模型登录用户。我也有一个控制器,使用我的模型。这是我的控制器
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); }
所以在这种情况下,我希望用户在点击按钮时登录。感谢
为动作属性指定正确的值。使用"电子邮件"值作为第一个文本框的id和名称
<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>
用HttpPost属性装饰:
[HttpPost]
public ActionResult LogIn(UserModel model)
{
//code
}