传递到字典中的模型项的类型为“OnlineShoppingSystemMVC.Models.User”,但此字典需要类型为“OnlineShoppingSystemMVC.Models.Repository”的模型项。 [英] The model item passed into the dictionary is of type 'OnlineShoppingSystemMVC.Models.User', but this dictionary requires a model item of type 'OnlineShoppingSystemMVC.Models.Repository'.

查看:114
本文介绍了传递到字典中的模型项的类型为“OnlineShoppingSystemMVC.Models.User”,但此字典需要类型为“OnlineShoppingSystemMVC.Models.Repository”的模型项。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能会问一个很多程序员可能已经问过的问题,但仍然在这里......



我有一个具有以下属性的模型用户

I may be asking a question that a lot of programmers might have asked but still here it goes..

I have the a model User with following properties

public string firstName { get; set; }
public string lastName { get; set; }
public string userName { get; set; }
public int userTypeID { get; set; }
public string email { get; set; }
public long phoneNumber1 { get; set; }
public long phoneNumber2 { get; set; }
public string address { get; set; }





在模型中 UserProfile()我用一个用户加载一个名为user的对象如上所示的详细信息并将其发送到视图



In the model UserProfile() I load an object named user with a user's details as shown above and send it to the view as

View(user);





我有创建了一个强类型视图





And I have created a strongly typed view as

@model OnlineShoppingSystemMVC.Models.User
@{
    ViewBag.Title = "UserProfile";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>UserProfile</h2>
<fieldset>
    <legend>User</legend>
    <div class="display-label">
@Html.DisplayNameFor(model => model.firstName)
    </div>
    <div class="display-field">
@Html.DisplayFor(model => model.firstName)
    </div>
    .
    .
    </fieldset>
<p>
    @Html.ActionLink("Edit", "Edit", new { /* id=Model.PrimaryKey */ }) |
    @Html.ActionLink("Back to List", "Index")
</p>







当我执行应用程序并重定向到视图时,它显示以下错误

传递到字典中的模型项的类型为'OnlineShoppingSystemMVC.Models.User',但此字典需要一个'OnlineShoppingSystemMVC.Models.Repository'类型的模型项目。



任何人都可以帮助解决我出错的地方吗?



感谢您提前获得任何支持。




When I execute the application and redirect to the view it showing the following error
The model item passed into the dictionary is of type 'OnlineShoppingSystemMVC.Models.User', but this dictionary requires a model item of type 'OnlineShoppingSystemMVC.Models.Repository'.

Can any one help out on where I went wrong?

Thanks for any support in advance.

推荐答案

这篇关于传递到字典中的模型项的类型为“OnlineShoppingSystemMVC.Models.User”,但此字典需要类型为“OnlineShoppingSystemMVC.Models.Repository”的模型项。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆