Using Telerik's Kendo UI, Kendo.Mvc version 2016.3.1028.545
I have a view that contains an html grid like so:
@(Html.Kendo().Grid<TfUserLoginHistoryReturnModel>()
.Name("loginHistoryGrid")
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("LoginHistory_Read", "Administration", new { DateStart = Model.StartDate }))
.Model(model => model.Id(p => p.UserID)
)
)
.Events(events => events.DataBound("onGridDataBound"))
.Columns(columns =>
{
columns.Bound(p => p.FullName).Title("Full Name");
columns.Bound(p => p.Email);
columns.Bound(p => p.CompanyName).Title("Company");
columns.Bound(p => p.UserType).Title("User Type");
columns.Bound(p => p.AcceptedTermsDate).Title("Date Accepted Terms").Format("{0:MM/dd/yyyy}").Width(125);
columns.Bound(p => p.LastSuccessfulLogin).Title("Last Login").Format("{0:MM/dd/yyyy}").Width(125);
columns.Bound(p => p.NumLogins).Title("Number of Logins");
columns.Bound(p => p.TotalTime).Title("Time Logged (minutes)");
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable(f => f.Extra(true)
.Operators(o => o.ForString(s => s.Clear()
.Contains("Contains")
.DoesNotContain("Does not contain")
.IsEqualTo("Is equal to")
.IsNotEqualTo("Is not equal to")
.StartsWith("Starts with")
.EndsWith("Ends with")
.IsEmpty("Is empty")
.IsNotEmpty("Is not empty")
.IsNull("Is null")
.IsNotNull("Is not null "))))
.HtmlAttributes(new { style = "height:500px;" })
)
Associated Scripts:
function onGridDataBound(e) {
var grid = e.sender;
if (grid.dataSource.total() == 0) {
$(grid).hide();
}
else {
$(grid).show();
}
}
function searchUserGrid(e) {
if ($("#userSearchText").val() == "") {
$("#loginHistoryGrid").data("kendoGrid").dataSource.filter({ field: "UserId", operator: "equals", value: -1 });
} else {
$filter = [{
"logic": "or",
"filters": [
{ field: "FullName", operator: "contains", value: $("#userSearchText").val() },
{ field: "Email", operator: "contains", value: $("#userSearchText").val() },
{ field: "CompanyName", operator: "contains", value: $("#userSearchText").val() }
]
}];
$("#loginHistoryGrid").data("kendoGrid").dataSource.filter($filter);
}
}
Here is the Get for that view in the controller:
[HttpGet]
public ActionResult UsageReport(string DateStart)
{
try
{
UserLoginHistoryViewModel m = new UserLoginHistoryViewModel();
//default is yesterday
DateTime sdt = DateTime.Now.Date.AddDays(-1);
if (!string.IsNullOrWhiteSpace(DateStart))
{
DateTime.TryParse(DateStart, out sdt);
}
m.StartDate = sdt;
return View(m);
}
catch (Exception ex)
{
logger.Error("UsageReportGet", ex);
return RedirectToAction("Index", "Administration");
}
}
When I run this with a breakpoint and go to that page, it doesn't even hit LoginHistory_Read
in the controller. While hitting the grid, it errors out. Here is the error and stack trace:
System.ArgumentException was unhandled by user code
HResult=-2147024809 Message=An item with the same key has already been added. Source=mscorlib StackTrace: at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary'2.Insert(TKey key, TValue value, Boolean add) at System.Web.Routing.RouteValueDictionary.Add(String key, Object value) at Kendo.Mvc.UI.GridBoundColumn'2.CreateHeaderBuilderCore() at Kendo.Mvc.UI.GridColumnBase'1.CreateHeaderBuilder() at Kendo.Mvc.UI.Html.GridCellBuilderFactory.CreateHeaderCellBuilder(IGridColumn column) at System.Linq.Enumerable.WhereSelectEnumerableIterator'2.MoveNext() at Kendo.Mvc.UI.Html.GridRowBuilder.CreateRow() at Kendo.Mvc.UI.Html.GridHeaderRowBuilder.CreateRow() at Kendo.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow() at Kendo.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow() at Kendo.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow() at Kendo.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow() at Kendo.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow() at Kendo.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow() at Kendo.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow() at Kendo.Mvc.UI.Html.GridDataSectionBuilder.CreateHeader(GridRenderingData data) at Kendo.Mvc.UI.Html.GridScrollingHtmlBuilder.CreateHeader(GridRenderingData renderingData) at Kendo.Mvc.UI.Html.GridScrollingHtmlBuilder.AppendData(IHtmlNode div, GridRenderingData renderingData) at Kendo.Mvc.UI.Html.GridHtmlBuilder.CreateGrid(IDictionary'2 htmlAttributes, GridFunctionalData functionalData, GridRenderingData renderingData) at Kendo.Mvc.UI.Grid'1.WriteHtml(HtmlTextWriter writer) at Kendo.Mvc.UI.WidgetBase.ToHtmlString() at Kendo.Mvc.UI.Fluent.WidgetBuilderBase'2.ToHtmlString() at System.Web.HttpUtility.HtmlEncode(Object value) at System.Web.WebPages.WebPageBase.Write(Object value) at ASP._Page_Views_Administration_UsageReport_cshtml.Execute() in C:\Users\tsimpson\Source\Workspaces\CustomerPortal\CEConnect\CEConnect\Views\Administration\UsageReport.cshtml:line 42 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at System.Web.WebPages.StartPage.RunPage() at System.Web.WebPages.StartPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList'1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList'1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
InnerException:
So if I run it without breakpoints, the page will load, but the grid is empty.
I have no idea how to know what it is trying to add to the dictionary at that point. I compared this to other grids in my site that do work, and don't see what it could be that's causing this issue.
This is a video I made of what walking through it looks like so you can see exactly at which point the error comes up - hopefully that helps. Be sure to set it to 1080p! Kendo Grid Error
Let me know what other information is needed to try and determine what it could be. Thank you!
public ActionResult UsageReport([DataSourceRequest] DataSourceRequest request,string DateStart)
– Akash KC