简体   繁体   中英

How to fetch data from a class with two list inside?

I have a class with 2 list inside and don't know how to fetch through all 2 list to get all data, thank you for reading my question.

my MODEL

namespace BaoCao.Models
{
    public class ProductPage
    {
        public List<PRODUCT> listproduct { get; set; }
        public List<TYPE_PRODUCTS> listtype_product { get; set; }

        public static ProductPage getAll()
        {
            DB db = new DB();
            ProductPage a = new ProductPage();
            a.listproduct = db.PRODUCTS.ToList();
            a.listtype_product = db.TYPE_PRODUCTS.ToList();
            return a;
        }
        ProductPage()
        {

        }

    }
}

MY VIEW

namespace BaoCao.Controllers
{
    public class ProductController : Controller
    {
        // GET: Product
        public ActionResult Product()
        {
            var dssp = ProductPage.getAll();
            return View(dssp);
        }
        
    }
}

Product.cshtml

@model BaoCao.Models.ProductPage
@foreach (var product in Model.listproduct) {
...
}

The details are here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM