我尝试在Razor页面中加载一个简单的网格,但是在页面加载时出现错误。我找不到可以帮助解决此错误的资源。
我确实注意到错误的第二行(请参见下面的完整错误)Kendo.Mvc.UI.Fluent.CrudOperationBuilderBase<TCrudOperationBuilder>.Action(string actionName, string controllerName, object routeValues)
表示Action方法期望在controllerName之后传递一个Object,但是所有文档都表明只有Action和控制器名称是必需的。任何见识或帮助将不胜感激。
这是我的错误
System.NullReferenceException: Object reference not set to an instance of an object.
at Kendo.Mvc.UI.Fluent.CrudOperationBuilderBase<TCrudOperationBuilder>.Action(string actionName, string controllerName, object routeValues)
at AspNetCore.Views_ExcludeCCNs_Index.<>c.<ExecuteAsync>b__9_3(CrudOperationBuilder read) in C:\Dev\2018.12.07\Prototypes\DBManagementUI\DBManagementUI\Views\ExcludeCCNs\Index.cshtml:line 19
at Kendo.Mvc.UI.Fluent.AjaxDataSourceBuilderBase<TModel, TDataSourceBuilder>.Read(Action<CrudOperationBuilder> configurator)
at AspNetCore.Views_ExcludeCCNs_Index.<>c.<ExecuteAsync>b__9_1(DataSourceBuilder<ExcludeCCN> dataSource) in C:\Dev\2018.12.07\Prototypes\DBManagementUI\DBManagementUI\Views\ExcludeCCNs\Index.cshtml:line 17
at Kendo.Mvc.UI.Fluent.GridBuilder<T>.DataSource(Action<DataSourceBuilder<T>> configurator)
at AspNetCore.Views_ExcludeCCNs_Index.ExecuteAsync() in C:\Dev\2018.12.07\Prototypes\DBManagementUI\DBManagementUI\Views\ExcludeCCNs\Index.cshtml:line 14
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)
这是我的 Kendo网格
@(Html.Kendo().Grid<DBManagementUI.Models.ExcludeCCN>()
.Name("grid")
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("ExcludeCCNs", "ExcludeCCNs"))
)
.Columns(columns =>
{
columns.Bound(product => product.CCN);
})
)
这是我的控制器
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI.Fluent;
using Kendo.Mvc.UI;
namespace Project.Controllers
{
public class ExcludeCCNsController : Controller
{
private readonly CWPAdminContext _context;
public ExcludeCCNsController(CWPAdminContext context)
{
_context = context;
}
private IEnumerable<ExcludeCCN> GetExcludeCCNs()
{
return _context.ExcludeCCN.Take(100).ToList();
}
public IActionResult ExcludeCCNs([DataSourceRequest]
DataSourceRequest request)
{
return Json(GetExcludeCCNs().ToDataSourceResult(request));
}
这是我的 Startup.cs文件
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddEntityFrameworkSqlServer().AddDbContext<ARCHContext>();
services.AddEntityFrameworkSqlServer().AddDbContext<CWPAdminContext>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseKendo(env);