How Do I Use A Tuple Properly in ASP.NET MVC 4

不羁的心 提交于 2019-12-06 00:59:22

Essentially, you're just trying to pass multiple models to your view. As you can only pass one type to a view, the way to do what you want is to wrap your models in a view model and pass that to your view instead. Something like:

public class ProductViewModel
{
    public IPagedList<Product> Products { get; set; }
    public IEnumerable<Order> Orders { get; set; }
}

public ActionResult Index()
{
    var model = new ProductViewModel();
    model.Products = // ... fetch from database
    model.Orders = // ... fetch from database

    return View(model);
}

The view can now be strongly-typed to the view model:

@model ProductViewModel
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!