English 中文(简体)
Automapper和MvcPager3共同工作
原标题:Automapper and MvcPager3 working together

I want to add Pagination to one of my views using MvcPager3. This would be simple, except that I m already using AutoMapper to map my model to a simplied viewmodel.

        List<Call> calls = (from p in db.Calls orderby p.ID descending select p).ToList();

        var viewModel = new List<CallListItem>();

        Mapper.Map(calls, viewModel);

        return View(viewModel);

我认为,替代这一行文可能非常简单。

var viewModel = new List<CallListItem>();

* E/CN.6/2009/1。

var viewModel = new PagedList<CallListItem>();

但是,PedList有一个建筑商,该建筑商拥有一份项目清单。 由于汽车在为我做这项工作,我认为我可能无法开车,但却没有工作。

人人都有和谐使用这两个组成部分的经验?

增 编

Edit:

创立了MvcPager称为PedList的替代品。 这比以往更糟,因为它有一个能够用于已经上页的数据的StaticPagedList阶层。

最佳回答

在绘制地图之后,你可以设想观点模式:

var calls = (from p in db.Calls orderby p.ID descending select p).ToList();
var viewModel = Mapper
    .Map<IEnumerable<Call>, IEnumerable<CallListItem>>(calls)
    .ToPagedList(currentPage, pageSize);
return View(viewModel);
问题回答

Alternately, you can paginate first and map afterwards by using StaticPagedList. This worked for me:

var calls = (from p in db.Calls orderby p.ID descending select p).ToPagedList();
var viewModel = Mapper.Map<IEnumerable<CallListItem>>(calls);
return new StaticPagedList<CallListItem>(viewModel, calls);

我之所以这样做,是因为我不想列出所有物体,以便稍后页。

http://michele.berto.li/using-automapper-with-pagedlist/“rel=“nofollow”。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签