错误传递到字典中的模型项的类型为';System.Data.Entity.DynamicProxies

本文关键字:System DynamicProxies Entity Data 字典 错误 模型 类型 | 更新日期: 2023-09-27 18:14:18

传递到字典中的模型项的类型为'System.Data.Entity.DynamicProxies.User_3B687608CE2EBE077B3CAB0EA66E20DFC054F09C758B6620E58A15CACB9B74E5',但是这本字典需要类型为的模型项'System.Collections.Generic.IEnumerable`1Models.UserPR]'.

这是我的代码:

控制器部分

public ViewResultBase ListUserPR(int idUser)
        {
            try
            {
                UserPRParameters parameters = new UserPRParameters();
                parameters.IdUser = idReuniao;
                base.SetViewBag(parameters);
                var model = this.UserPRServices.FindByUserPR(parameters);
                this.ViewBag.IdParameters = parameters.IdParameters;
                return this.ListView(model);
            }
            catch (ValidationException exception)
            {
                base.AddValidationErrors(exception);
                return base.PopUpSuccessView();
            }
        }

服务类别

public IEnumerable<UserPR> FindByUserPR(UserPRParameters parameters)
        {
            try
            {
                var query = base.context.UsersPrs.AsQueryable();
                query = query.Where(x => x.IdUser== parameters.IdUser);
                return query
                    .Sort(parameters, x => x.IdUser)
                    .Paginate(parameters);
            }
            catch (Exception exception)
            {
                throw new Exception(this.context.Database.Connection.ConnectionString, exception);
            }
        }

部分视图_ListUserPR内部视图"管理">

@model IEnumerable<UserPR>
@{
    var idGrid = "grid" + this.ViewBag.IdParameters ?? string.Empty;
    var user = this.Model.FirstOrDefault();
    int? userId = 0;
    if (null != user)
    {
        userId= user.IdUser;
    }
    var grid = new IBM.Web.Helpers
        .WebGrid(
                //source: this.Model,
                id: idGrid, rowsPerPage: this.RowsPerPage,
                ajaxUpdateContainerId: idGrid
                );
    var columns = new WebGridColumn[] {
        grid.Column("XXXX", UserPRResources.xxx, style: "center"),
        grid.Column("XXXX", UserPRResources.xxx, style: "center"),
        grid.Column("XXXXX", UserPRResources.xxx, style: "center"),
        ....

视图管理和控制器

@model User
@{
    var id = "id" + Guid.NewGuid().ToString().Substring(0, 5);
    this.ViewBag.Title = UserResources.Management;
}
<div class="box-fields">
    @using (Ajax.BeginForm(
        this.DefaultActionCreate,
        "User",
        new DefaultAjaxOptions()
    ))
    {
        @Html.Partial("Validation")
          section">@Resources.ReuniaoResources.ListUser</h2>
            @Html.Partial("ListUserPR")

控制器

public ViewResultBase Management(int id)
        {
            var model = this.Service.Get(id);
            return base.SwitchView(model);
        }

服务

public User Get(int id)
        {
            return this.context.Users.Find(id);
        }

我有两张桌子

UserPR中的用户>FK
UserPR没有PK-它是两个关系表(User和PR(

错误传递到字典中的模型项的类型为';System.Data.Entity.DynamicProxies

的结果

我认为您可以禁用创建代理

Configuration.ProxyCreationEnabled = false;

在dbcontext构造函数