首页 新闻 会员 周边

MVC传入字典的模型项的类型问题

0
悬赏园豆:10 [已解决问题] 解决于 2018-06-01 09:22

本人是.NET小白,刚入坑MVC,想像各位大神请教一下一个问题。

传入字典的模型项的类型为“OpenAuth.Mvc.Models.DataPageInfo`1[System.Collections.Generic.List`1[OpenAuth.Mvc.Models.AdminModel.LogModel]]”,但此字典需要类型“System.Collections.Generic.List`1[OpenAuth.Mvc.Models.AdminModel.LogModel]”的模型项

controller中:

var list = QueryLogsByCondition(token, userUID).Data;

return View(list);

public ResponseDataPageInfo<List<LogModel>> QueryLogsByCondition(string token, Guid userUID){代码};

 

model中:

 public class ResponseDataPageInfo<T>
    {
        public DataPageInfo<T> Data { get; set; }
        public bool IsSuccess { get; set; }
        public string Code { get; set; }
        public string Description { get; set; }
        public string ErrorMessage { get; set; }
    }

    //  分页信息
    public class DataPageInfo<T>
    {
        //分页信息
        public Pageinfo PageInfo { get; set; }

        //响应数据集合
        public List<T> List { get; set; }
    }


    ///  分页信息
    public class Pageinfo
    {
        // 总条数
        public int TotalCount { get; set; }

        //总页数
        public int PageCount { get; set; }

    }

 

View中:

@model List<OpenAuth.Mvc.Models.AdminModel.LogModel>

@section header

网上说是View与Model类型不一致,那这样的话,应该return什么呢?望各位大神不吝赐教,先谢谢了

Edward華的主页 Edward華 | 初学一级 | 园豆:143
提问于:2018-05-30 09:39
< >
分享
最佳答案
1

var list = QueryLogsByCondition(token, userUID).Data;

 

》》》

 

var list = QueryLogsByCondition(token, userUID).Data.List;

收获园豆:10
西漠以西 | 小虾三级 |园豆:1675 | 2018-05-30 11:12
其他回答(1)
0

//在服务层中要创建分页类  字段如下:

 public int pageindex { get; set; }

        public int pagesize { get; set; }

        public int pagecount { get; set; }

        public int sizecount { get; set; }

        publicList<NewsList> list = newList<NewsList>();

//在控制器中的写法

 public ActionResult Index(int index=1)

        {

            int size = 3;

            DataPager data = Client.ShowNews(index,size);

            return View(data);

        }

//在页面头部上写

@model MvcApplication1.ServiceReference1.DataPager

大黄人 | 园豆:641 (小虾三级) | 2018-05-30 10:01

现在是调用第三方接口WebAPI获取数据的,那样的话,如何单纯在Web层创建分页类?

支持(0) 反对(0) Edward華 | 园豆:143 (初学一级) | 2018-05-30 10:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册