I have a simple grid that I am trying to load in my Razor page, but I am getting an error when the page loads. I cannot find a resource that can help with this error.
I did notice that the second line of the error (see full error below) Kendo.Mvc.UI.Fluent.CrudOperationBuilderBase<TCrudOperationBuilder>.Action(string actionName, string controllerName, object routeValues)
is indicating that the Action method is expecting an Object to be passed after the controllerName, but all the documentation indicates that only the Action and Controller names are needed. Any insight or help would be greatly appreciated.
Here is my Error
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)
Here is my Kendo Grid
@(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);
})
)
Here is my Controller
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));
}
Here is my Startup.cs file
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);