【问题标题】:Kendo MVC Ajax Grid : Values are not showingKendo MVC Ajax Grid:值未显示
【发布时间】:2013-11-08 09:17:19
【问题描述】:

net mvc4 项目与 Kendo UI iam 使用简单的 ajax 网格从数据库中打印值,但它没有显示在网格上我的代码是

<%: Html.Kendo().Grid<CustomerTest.Models.ProductViewModel>()
   .Name("grid")
      .DataSource(dataSource => dataSource
          .Ajax()
          .Read(read => read
                   .Action("Printc", "Home") // Set the action method which will return the data in JSON format
              // .Data("productsReadData") // Specify the JavaScript function which will return the data
          )
      )
      .Columns(columns =>
      {
          columns.Bound(product => product.CustomerID);
          columns.Bound(product => product.CustomerFName);
          columns.Bound(product => product.CustomerLName);
      })
      .Pageable()
      .Sortable()
%>

我的操作方法是

 public ActionResult Printc()
    {
       // ViewBag.Message = "Welcome to ASP.NET MVC!";

        return View(GetCustomers());
    }

    private static IEnumerable<ProductViewModel> GetCustomers()
    {
        var northwind = new CustomerLinqDataContext();
        var purchCount = northwind.Customer_details.Count();
        return northwind.Customer_details.Select(product => new ProductViewModel
        {
           CustomerID   = product.ID,
             CustomerFName = product.name,
             CustomerLName = product.lname,
             CustomerAge = product.age 

        });
    }

请有人帮我把我做错了什么?我试图在页眉上传递我的模型

 <%@ Page Title="" Language="C#" MasterPageFile="~/Areas/aspx/Views/Shared/Web.Master" 
    Inherits="System.Web.Mvc.ViewPage<IEnumerable<CustomerTest.Models.ProductViewModel>>" %> 

它工作得很好,但我的单个页面上有多个网格,它们来自不同的表,所以这就是为什么我想以不同的方式传递每个模型请有人在这段代码中帮助我谢谢

【问题讨论】:

    标签: c# asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 kendo-ui


    【解决方案1】:

    问题出在您的 Printc 方法上。您必须返回为 Kendo Grid 创建的 Json 对象:

    public ActionResult Index_Printc([DataSourceRequest] DataSourceRequest request)
    {
        return Json(GetCustomers().ToDataSourceResult(request));
    }
    

    在我这边,我在Ajax请求上指定了ID,不知道是不是读取请求的强制,但是如果方法的更新不起作用,添加这个:

    <%: Html.Kendo().Grid<CustomerTest.Models.ProductViewModel>()
       .Name("grid")
          .DataSource(dataSource => dataSource
              .Ajax()
              .Model(model => model.Id(p => p.CustomerID))
              .Read(read => read.Action("Printc", "Home") 
              )
          )
          .Columns(columns =>
          {
              columns.Bound(product => product.CustomerID);
              columns.Bound(product => product.CustomerFName);
              columns.Bound(product => product.CustomerLName);
          })
          .Pageable()
          .Sortable()
    %>
    

    希望对你有帮助!

    【讨论】:

    【解决方案2】:

    如果您在同一页面上有多个网格,请确保它们具有唯一的名称,并且并非所有网格都称为网格。

    【讨论】:

      猜你喜欢
      • 2015-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多