【问题标题】:asp core kendo ui grid not showing dataasp core kendo ui网格不显示数据
【发布时间】:2018-11-10 22:51:56
【问题描述】:

我有一个剑道 ui 网格,它使用剃刀模型来获取其数据。网格显示正确的列名,但是,它没有显示任何数据。我可以验证是否正在返回数据,但网格没有呈现它。我关注了这个样本:Link to sample,

下面是启动、控制器和cshtml页面的代码。

项目在 .NET Core 2.0 上运行,控制器继承自 Microsoft.AspNetCore.Mvc.Controller,其中示例继承自 BaseController。

任何帮助表示赞赏!提前致谢。

Startup.cs - 配置:

    // Configure Kendo UI
    app.UseKendo(env);

Startup.cs - 配置服务:

services.AddMvc()
        .AddJsonOptions(options =>
         options.SerializerSettings.ContractResolver = new DefaultContractResolver());

        //Add Kendo UI services to the services container
        services.AddKendo();

控制器:

 var response = _personService.LoadById(id).Result;
 return View(response);

CSHTML:

    @(Html.Kendo().Grid<Pet>(Model.Person.Pets)
                   .Name("Grid")
                   .Columns(columns =>
                   {
                       columns.Bound(p => p.Name).Title("Pet Name");
                   })
                   .Pageable()
                   .Sortable()
                   .Scrollable(scr => scr.Height(430))
                   .Filterable()
                   .DataSource(dataSource => dataSource
                       .Ajax()
                       .PageSize(20)
                       .ServerOperation(false)
                    )
                )

【问题讨论】:

    标签: asp.net-core kendo-ui telerik-grid kendo-ui-grid


    【解决方案1】:

    您需要指定 IEnumerable 作为视图的模型,然后您可以像这样传递数据:

    控制器动作:

        public IActionResult Index()
        {
            var petList = new List<Pet>();
    
            petList.Add(new Pet { Name = "Cat" });
            petList.Add(new Pet { Name = "Dog" });
    
            return View(petList);
        }
    

    索引.cshtml

    @model IEnumerable<TelerikAspNetCoreApp1.Models.Pet>
    
    <div class="row">
        <div class="col-xs-18 col-md-12">
            @(Html.Kendo().Grid(Model)
                .Name("petgrid")
                .Columns(columns =>
                {
                    columns.Bound(p => p.Name);
                })
                .Pageable()
                .Sortable()
                .Scrollable()
                .Filterable()
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .PageSize(20)
                )
            )
        </div>
    </div>
    

    【讨论】:

      猜你喜欢
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多