2

我希望在一个视图中显示两个具有不同信息(模型)的 Telerik Kendo 网格,但我不知道该怎么做。

模型:

using System.Collections.Generic;

namespace KendoUIMvcApplication1.Models
{
    public class Car
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    public class Truck
    {
        public int Id { get; set; }
         public string Name { get; set; }
    }

    public class Vehicles
    {
        public IEnumerable<Car> CarCol { get; set; }
        public IEnumerable<Truck> TruckCol { get; set; }
    }
}

控制器(创建一些测试对象):

using System.Collections.Generic;
using System.Web.Mvc;
using KendoUIMvcApplication1.Models;

namespace KendoUIMvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var carList = new List<Car>();
            var truckList = new List<Truck>();
            var vehCol = new Vehicles();

            var car1 = new Car
            {
                Id = 1, 
                Name = "Passat"
            };
            var car2 = new Car
            {
                Id = 2,
                Name = "Passat"
            };
            carList.Add(car1);
            carList.Add(car2);

            var truck1 = new Truck
            {
                Id = 1,
                Name = "S10"
            };
            var truck2 = new Truck
            {
                Id = 1,
                Name = "Blazer"
            };
            truckList.Add(truck1);
            truckList.Add(truck2);

            vehCol.CarCol = carList;
            vehCol.TruckCol = truckList;

            return View(vehCol);
        }
    }
}

查看(这里我试图显示两个网格。第一个用于汽车,第二个用于卡车):

@using KendoUIMvcApplication1.Models

@model IEnumerable<Vehicles>

@*// Car Grid*@
@(Html.Kendo().Grid(Model)
    .Name("Grid")
    .Columns(columns => {
        columns.Bound(c => c.Id);
        columns.Bound(c => c.Name);
    })
)

<div></div>

@*// Truck Grid*@
@(Html.Kendo().Grid(Model))
    .Name("Grid")
    .Columns(columns => {
        columns.Bound(t => t.Id);
        columns.Bound(t => t.Name);
    })
)
4

1 回答 1

2

您的模型应该是类型Vehicles

@model Vehicles

然后您可以访问这两个集合:

@Html.Kendo().Grid(Model.CarCol)
...

@Html.Kendo().Grid(Model.TruckCol)
...
于 2012-12-07T19:49:30.800 回答