1

I'm trying to populate a kendo grid within a kendo window in MVC and am unable to find what is wrong. The window is created, and the grid is created within the window... however the DataSource's Read method is never called.

Window:

@{    
Html.Kendo().Window()
           .Name("DListing")
           .Title("Listing")
           .Draggable()
           .Resizable()
           .Width(1000)
           .Height(500)
           .Visible(true)
           .Modal(true)
           .Actions(actions => actions
                .Maximize()
                .Close())
           .LoadContentFrom("Dispatch", "Listing", new { Number = @ViewBag.Number })
           .Render();}

The Dispatch method in the Listing controller returns back a partial view that contains the grid.

Grid:

 @(Html.Kendo().Grid(Model)
        .Name("Grid")
        .Events(events => events.Change("onChange"))
        .HtmlAttributes(new { style = "height:400px;" })
        .Columns(columns =>
        {
            columns.Bound(p => p.Number);
            columns.Bound(p => p.DateTime).Format("{0:MM/dd/yyyy hh:mm tt}");
            columns.Bound(p => p.Location);
            columns.Bound(p => p.Name);
            columns.Bound(p => p.Elapsed_Hours);

        })
        .Groupable()
        .Pageable(pageable => pageable
            .Numeric(false)
            .Input(true)
            .PageSizes(new[] { 5, 10, 25 }))
        .Sortable()
        .Scrollable(scrollable => scrollable
            .Virtual(true))
        .Filterable()
        .Selectable(selectable => selectable
            .Mode(GridSelectionMode.Multiple))
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(13)
            .Sort(sort => { sort.Add(p => p.DateTime).Descending(); })
            .Model(model => { model.Id(p => p.Number); })
            .Read(read => read.Action("Listing_Read", "Listing", new { Number = @ViewBag.Number })))
        )

Listing_Read Method:

    public ActionResult Listing_Read([DataSourceRequest] DataSourceRequest request, int Number)
    {
        return Json(GetListing(branchNumber).ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
    }

Also, it should be noted that I went through and verified that the viewbag data is available for both the window and later on in the grid.

For a little more back info, I initially had the grid on it's own page and it was able to call the read method and populated with the data with no issues. After moving it to populate in the window is when this became a problem.

Monitoring the http requests, the grid never attempts to call the read method (so the request isn't failing). I tried manually refreshing the datasource after the window has loaded thinking that might force the call, but that doesn't call the read method either.

I've been scratching my head on this one for a few hours now trying different things, hoping someone can spot what the problem is :)

4

1 に答える 1

1

これが私のために働いたものです:

1) ビュー (~/Views/Home/Index.cshtml)

@(Html.Kendo().Window()
  .Name("myWindow")
  .Title("Title")
  .Actions(actions => actions.Pin().Minimize().Maximize().Close())
  //.Content(Html.Partial("gridCat").ToHtmlString())
  .LoadContentFrom("Load_gridCat", "Home")

)

2) 部分ビュー (~/Views/Shared/gridCat.cshtml)

@(Html.Kendo().Grid<TelerikMvcApp1.Models.Category>()
  .Name("CategoriesGrid")
  .Columns(columns =>
  {
     columns.Bound(c => c.CategoryID).Title("Category").Width("10%");
     columns.Bound(c => c.CategoryName);
     columns.Bound(c => c.Description);
  })
  .Filterable()
  .Pageable()
  .Sortable()
  .Scrollable()
     .DataSource(dataSource => dataSource
     .Ajax()
     .Model(model => model.Id(p => p.CategoryID))
     .Read(r => r.Action("Categories_Read", "Home"))
  )
  .HtmlAttributes(new { style = "height:250px" })

)

3) コントローラー (~/Controllers/HomeController.cs)

public ActionResult Load_gridCat()
{
   return PartialView("gridCat");
}

public ActionResult Categories_Read([DataSourceRequest]DataSourceRequest request)
{
   using (var ctx = new NWindContext())
   {
      IQueryable<Category> categories = ctx.Categories;

      DataSourceResult result = categories.ToDataSourceResult(request);
      return Json(result, JsonRequestBehavior.AllowGet);
   }
}
于 2014-04-03T16:12:48.633 に答える