这是我的控制器
public ActionResult Index(Models.boss ob)
{
ViewBag.Bid = new SelectList(db.bosses, "Bid", "username");
var mm = db.bosses.Any(model => model.username == ob.username && model.password == ob.password);
if (mm)
{
return RedirectToAction("welcome");
}
else
{
ModelState.AddModelError("", "Login data is incorrect!");
}
return View(ob);
}
这是我的Index.View我验证了所有内容,但在这样的网页上显示相同
登录失败。检查您的登录详细信息登录数据不正确!
那我做错了什么?
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "Login failed. Check your login details.");
<div class="editor-field">
@Html.LabelFor(model => model.username)
@Html.EditorFor(model => model.username)
@Html.ValidationMessageFor(model => model.username)
</div>
<div>
@Html.ValidationMessageFor(m => m.username)
</div>
<div class="editor-field">
@Html.LabelFor(model => model.password)
@Html.PasswordFor(model => model.password, "password=*")
</div>
<div>
<label>SELECT USER</label>
@Html.DropDownList("boss", ViewBag.Bid as SelectList, "Select a User", new { id = "boss" })
</div>
<button>LOGIN</button>
}
答案 0 :(得分:0)
服务器端错误:"Login data is incorrect!"
,写在控制器中。
客户端您已在ValidationSummary中设置了初始错误"Login failed. Check your login details."
。
请删除初始客户端验证消息。
您还必须在动作调用中传递 [ValidateAntiForgeryToken] 令牌参数。