1

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?

5
  • From the error you posted it looks like you have a conflict of two classes. They are both named RegisteredUser. One resides in the ProjectyMcProjectface and the other in ProjectyMcProjectface.Models. That's what is causing the ambiguity. I will suggest you rename one of them Commented Jul 24, 2017 at 12:16
  • @jamiedanq yes, thank you, it worked! Commented Jul 24, 2017 at 12:36
  • Glad it solved it! Commented Jul 24, 2017 at 13:58
  • Can you please mark my comment as helpful Commented Jul 24, 2017 at 14:27
  • @jamiedanq I'm afraid I don't know how Commented Jul 25, 2017 at 8:44

1 Answer 1

1

It seems to be path of Edm has been changed some how. Please check the edm location whether it is ok and clean and rebuild the project

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.