I'm creating a login window and problem appears when pressing submit button after entering wrong credentials. Here is my view
@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>
my registered user model
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; }
}
and my login controller
[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();
}
the error fires in line
var userDetails = db.RegisteredUsers.Where(x => x.UserName == userModel.UserName && x.PassWord == userModel.PassWord).FirstOrDefault();
and says
The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'RegisteredUser'. Previously found CLR type 'ProjectyMcProjectface.RegisteredUser', newly found CLR type 'ProjectyMcProjectface.Models.RegisteredUser'.'
How can I solve this?
ProjectyMcProjectfaceand the other inProjectyMcProjectface.Models. That's what is causing the ambiguity. I will suggest you rename one of them