' System.Data.Entity.DynamicProxies.User _',此字典需要类型为' System.Collections.Generic.IEnumerable`1 [Oblig1.Models.Item]'的模型项。

时间:2014-10-10 10:12:08

标签: c# asp.net asp.net-mvc visual-studio

我目前收到错误“传入字典的模型项的类型为'System.Data.Entity.DynamicProxies.User_546F9926F8DC53E2EF66BA48BE431DF1B26DEBEFA54B0597E60AEB1839DD022C',但此字典需要类型为'System.Collections.Generic.IEnumerable`的模型项1 [Oblig1.Models.Item]”。“

我正在尝试用一个用户列出视图_Minside.html,但是仍然会收到此错误,任何人都可以伸出援助之手?

_Minside.html:

@model Oblig1.Models.User

<table class="table">
    @Model.Firstname
    @Model.Surname
    @Model.Email
    @Model.Address
    @Model.Password
    @Model.Phonenr
    @Model.Postcode
</table>

这是Minside.html的一部分内容:

@model Oblig1.Models.User
<br />
<br />
<br />

<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li class="active"><a href="#home" role="tab" data-toggle="tab">Kontoinformasjon</a></li>
<li><a href="#profile" role="tab" data-toggle="tab">Ordrehistorikk</a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
    <div class="tab-pane active" id="home">
        <br />
        <br />

        @Html.Partial("_Minside")

    </div>
<div class="tab-pane" id="profile">Ordrehistorikk</div>
<div class="tab-pane" id="messages">...</div>
<div class="tab-pane" id="settings">...</div>
</div>

此视图由包含此模型的视图_Layout中的链接打开:

@model IEnumerable<Oblig1.Models.Item>
@Html.ActionLink("  MinSide", "Minside", "", new { @class = "glyphicon glyphicon-user" })

UserController中:

    public ActionResult Minside()
    {
        var db = new PastaContext();

        string compareEmail = (string)Session["User"];
        User foundUser = db.Users.Find(compareEmail);

        if(foundUser == null)
        {
            return RedirectToAction("Index");
        }
        else
        {
            return View(foundUser);
        }           
    }

0 个答案:

没有答案