我正在创建一个登录窗口,输入错误的凭据后按提交按钮会出现问题。 这是我的观点
@model ProjectyMcProjectface.Models.RegisteredUser
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Login page</title>
@Styles.Render("~/Content/LoginVisuals")
</head>
<body>
<div id="LoginWrapper">
@using (Html.BeginForm("Authorize", "Login",FormMethod.Post))
{
<table id="LoginTable">
<tr>
<td>@Html.LabelFor(model => model.UserName)</td>
<td>@Html.EditorFor(model => model.UserName)</td>
</tr>
<tr>
<td></td>
<td>@Html.ValidationMessageFor(model => model.UserName)</td>
</tr>
<tr>
<td>@Html.LabelFor(model => model.PassWord)</td>
<td>@Html.EditorFor(model => model.PassWord)</td>
</tr>
<tr>
<td></td>
<td>@Html.ValidationMessageFor(model => model.PassWord)</td>
</tr>
<tr>
<td colspan="2"><label class="field-validation-error">@Html.DisplayFor(model => model.LoginErrorMessage)</label></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Login" />
<input type="reset" value="Clear" />
</td>
</tr>
</table>
}
</div>
@Scripts.Render("~/bundles/ValidationScripts")
</body>
</html>
我的注册用户模型
public partial class RegisteredUser
{
public int Id { get; set; }
[DisplayName("User Name")]
[Required(ErrorMessage = "This field is required to be filled")]
public string UserName { get; set; }
[DataType(DataType.Password)]
[DisplayName("Password")]
[Required(ErrorMessage = "This field is required to be filled")]
public string PassWord { get; set; }
public string LoginErrorMessage { get; set; }
}
和我的登录控制器
[HttpPost]
public ActionResult Authorize(ProjectyMcProjectface.Models.RegisteredUser userModel)
{
using (InternalDBEntities1 db = new InternalDBEntities1())
{
var userDetails = db.RegisteredUsers.Where(x => x.UserName == userModel.UserName && x.PassWord == userModel.PassWord).FirstOrDefault();
if (userDetails == null)
{
userModel.LoginErrorMessage = "Your password or user name is incorrect";
return View("Index", "Login", userModel);
}
}
return View();
}
错误在线
var userDetails = db.RegisteredUsers.Where(x => x.UserName == userModel.UserName && x.PassWord == userModel.PassWord).FirstOrDefault();
并说
CLR类型到EDM类型的映射是不明确的,因为多个CLR 类型匹配EDM类型'RegisteredUser'。以前发现CLR类型 'ProjectyMcProjectface.RegisteredUser',新发现的CLR类型 'ProjectyMcProjectface.Models.RegisteredUser''。
我该如何解决这个问题?
答案 0 :(得分:0)