【问题标题】:The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.Tbl_Categorys传入字典的模型项的类型为 'System.Data.Entity.DynamicProxies.Tbl_Categorys
【发布时间】:2021-03-08 18:25:33
【问题描述】:

我的网站有问题。我从控制器返回一个值以查看,但它不起作用并显示此消息:

传入字典的模型项是类型 'System.Data.Entity.DynamicProxies.Tbl_Categorys_26FAF8D301E15B0158E967BAE1EAE74FFE13A2BB70503E270542F343CFB2ADAB', 但是这本字典需要一个类型的模型项 'RanaShop.Models.Domain.Tbl_User

public ActionResult Product(int id)
{
    var q = (from a in db.Tbl_Categorys
             where a.ID.Equals(id) && (a.ExitCount > 0)
             select a).SingleOrDefault();
    if (q == null)
    {
        ViewBag.Message = "No product to show";
        ViewBag.Class = "alert alert-danger";
        ViewBag.Style = "width: 40%;padding:15px;background-color:rgb(248,215,218);border 
                                             radius:5px;text-align:right;top:20px;margin:0 auto";

        return View();

    }
    return View(q);
}

查看

@model RanaShop.Models.Domain.Tbl_Categorys

@{
    ViewBag.Title = @Model.Title;
    Layout = "~/Views/Shared/_Layout.cshtml";
    RanaShop.Models.Domain.ranaDBEntities db = new RanaShop.Models.Domain.ranaDBEntities();

}

<div style="@ViewBag.Style" class="@ViewBag.Class">
    @if (ViewBag.Style != null)
    {
        <button type="button" class="close" data-dismiss="alert" style="float:left">×</button>
    }
    @Html.Raw(ViewBag.Message)
</div>
@{
    if (Model != null)
    {
        <div class="container padding-top-10 ">
            <div class="col-md-7 col-sm-7 col-xs-12">
                <div class="well">
                    <strong>
                        @Model.Title
                    </strong>
                    <p class="help-block ">
                        @Model.City
                    </p>
                </div>
                <span class="line-height-30 " style="font-family:'B Titr'">
                    @Html.Raw(Model.Text)

                </span>
                <hr />
                <div class="shop-item-price padding-bottom-10 ">

                    <span>
                        <strong>
                            Price : @Model.Price Dollor
                        </strong>

                    </span>

                </div>
            </div>
        </div>
    }
    else
    {
        <p>
           No product to show
        </p>
    }
}
}

我该如何解决?

【问题讨论】:

标签: c# .net asp.net-mvc model-view-controller razor


【解决方案1】:

我解决了我的问题并在布局上出现问题。 我不应该将布局中的模型提供给 Tbl_User 。我必须把它交给 Tbl_Category,现在可以了。

【讨论】:

    猜你喜欢
    • 2019-06-01
    • 2021-10-01
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多