Hi @Coreysan ,
InventoryViewModel myVM = new InventoryViewModel {
Inventory = all_inventory.Skip(5),
PagingInfo = new PagingInfo ........
Try to modify the code as below:
InventoryViewModel myVM = new InventoryViewModel
{
Inventory = all_inventory.Select(c=> new Inventory() { Id = c.Id, Name= c.Name}).Skip(5).ToList(),
PagingInfo = new PagingInfo() ...
};
Besides, you can also modify the controller code as below: change the all_inventory data type from IEnumerable<IInventory>
to IEnumerable<Inventory>
:
IEnumerable<Inventory> all_inventory = from m in mydb.Inventory select m;
In this scenario, there is no need to use the select
statement when create the InventoryViewModel model instance.
Finally, please check your view model, it should like this:
public class InventoryViewModel {
public IEnumerable<Inventory> Inventory { get; set; }
public PagingInfo PagingInfo { get; set; }
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion