我最近将Kendo.Mvc用于我的项目。我正在使用NuGet的Kendo.Mvc v2016.2.616
但是我使用它时出错了。
这是我的.cshtml
文件
@(Html.Kendo().Grid<TestViewModel>()
.Name("TestGrid")
.Columns(columns =>
{
columns.Bound(x => x.Id).Hidden(true);
columns.Bound(x => x.SomeString).Width(480);
columns.Bound(x => x.SomeBigInt).Width(100);
columns.Bound(x => x.SomeDate).Width(200);
})
.Scrollable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(new int[] { 10, 20, 40, 60, 80, 100 })
.ButtonCount(6))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetGridData", "Test"))
.PageSize(20)
)
)
这里是我的Controller
Public class TestController : Controller
{
public IActionResult GetGridData([DataSourceRequest]DataSourceRequest request)
{
return Json(service.GetGridData(request));
}
}
我已经在_ViewImports.cshtml
和_ViewStart.cshtml
中添加了引用
像这样:
_ViewImports.cshtml
@using Web
@using Application.ViewModels
@using Kendo.Mvc.UI
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Kendo.Mvc
_ViewStart.cshtml
@{
Layout = "_Layout";
}
@using Kendo.Mvc.UI;
这是堆栈跟踪
System.NullReferenceException: Object reference not set to an instance of an object.
at Kendo.Mvc.UI.Fluent.CrudOperationBuilderBase`1.Action(String actionName, String controllerName, Object routeValues)
at AspNetCore.Views_Test_Index.<>c.<ExecuteAsync>b__0_7(CrudOperationBuilder read) in Path\Index.cshtml:line 29
at Kendo.Mvc.UI.Fluent.AjaxDataSourceBuilderBase`2.Read(Action`1 configurator)
at AspNetCore.Views_Test_Index.<>c.<ExecuteAsync>b__0_2(DataSourceBuilder`1 dataSource) in Path\Index.cshtml:line 27
at Kendo.Mvc.UI.Fluent.GridBuilder`1.DataSource(Action`1 configurator)
at AspNetCore.Views_Test_Index.ExecuteAsync() in Path\Index.cshtml:line 12
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable`1 statusCode)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
谢谢