Мне нужно отобразить две сетки кендо с одинаковой структурой, но разными данными на одной странице.Поскольку это одна и та же сетка с отличающимися только данными, я решил поместить ее в частичное представление и повторно использовать.
Вот так выглядит сетка.Если вы видите, что оба грида вызывают один и тот же метод read
в контроллере, но с другим параметром.
@(Html.Kendo().Grid<KitchenSink.Models.ViewModel.ConsolidatedTopNViewModel>()
.Name(gridName)
.Columns(column =>
{
// Columns
})
.DataSource(dataSource => dataSource
.Ajax()
.Group(g => g.Add(m => m.GroupID))
.Read(read => read.Action("ConsolidatedTopNPartialPage_Read", "Visuals", new { year = ViewBag.year})) )
.Events(e => e.DataBound("consolidatedTopNDataBound")
.ExcelExport("excelExport"))
)
И в контроллере
public ActionResult ConsolidatedTopNPartialPage_Read([DataSourceRequest] DataSourceRequest request, int year)
{
List<ConsolidatedTopNViewModel> consolidated = opportunityService.ConsolidatedTopN(year);
return Json(consolidated.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
Эта установка работает нормальнокроме одного из сетки иногда не загружается.Я получаю исключение в методе Json
, например
Исключение типа 'System.ArgumentException' произошло в mscorlib.dll, но не было обработано в коде пользователя
Дополнительная информация: Элемент с тем же ключом уже добавлен.
Модель ConsolidatedTopNViewModel
представляет собой простой ViewModel и не имеет никакого первичного ключа или обязательного поля, связанного с ним, для использования в качестве ключа.по умолчанию.
Модель:
public class ConsolidatedTopNViewModel
{
public int Year { get; set; }
public int GroupID { get; set; }
public string Primary_Owner { get; set; }
public string Category { get; set; }
public string Initiative { get; set; }
public string Description_Assumptions { get; set; }
public decimal? OpportunityRunRate { get; set; }
public decimal? OpportunityCumulative { get; set; }
public decimal? ForecastRunRate { get; set; }
public decimal? ForecastCumulative { get; set; }
public decimal? RemainingRunRate { get; set; }
public decimal? RemainingCumulative { get; set; }
public ConsolidatedTopNViewModel()
{
GroupID = 2;
}
}
Трассировка стека
в System.ThrowHelper.ThrowArgumentException (ресурс ExceptionResource) в System.Collections.Generic.Dictionary 2.Insert(TKey
key, TValue value, Boolean add) at
System.Collections.Generic.Dictionary
2.Добавить (ключ TKey, значение TValue)
в Kendo.Mvc.Infrastructure.Implementation.ClassFactory.GetDynamicClass (IEnumerable 1
properties) at
Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateProjectionNewExpression(IEnumerable
1 propertyValuesExpressions) в Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptilExpressionExpateKendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateAggregateFunctionsProjectionMemberBinding () в Kendo.Mvc.Infrastructure.Implementation.Expressions.QueryableAggregatesExpressionBpileBuilder *. *. 10.в System.Dynamic.Utils.CollectionExtensions.ToReadOnly [T] (IEnumerable 1
enumerable) at
System.Linq.Expressions.Expression.MemberInit(NewExpression
newExpression, IEnumerable
1 привязок) в Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateSelectBodyExpression () в Kendo.Mvc.Infrastruct.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateSelectExpression () в Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilderBase.CreateQuery () в Kendo.Mvc. * расширяемый объект (можно использовать).Mvc.Extensions.QueryableExtensions.ToDataSourceResult (IQueryable queryable, запрос DataSourceRequest, ModelStateDictionary modelState) в Kendo.Mvc.Extensions.QueryableExtensions.ToDataSourceResult (IQueryable Keys DataSourceRequest).запрос) в KitchenSink.Controllers.VisualsController.ConsolidatedTopNPartialPage_Read (запрос DataSourceRequest, Int32 года) в p: \ KitchenSink-test \ KitchenSink \ Controllers \ VisualsController.cs: строка 101 в lambda_method (Closure, ControllerBase, Object []].Mvc.ActionMethodDispatcher.Execute (ControllerBase controller, OПараметры bject []) в System.Web.Mvc.ReflectedActionDescriptor.Execute (параметры ControllerContext controllerContext, IDictionary 2 parameters) at
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext
controllerContext, ActionDescriptor actionDescriptor, IDictionary
2) в System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation.InvokeSynchronousActionMethod.v) (at).AsyncControllerActionInvoker.b__39 (IAsyncResult asyncResult, ActionInvocation innerInvokeState) в System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 2.CallEndDelegate(IAsyncResult
asyncResult) at
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase
1.End () в System.Web.MvynSesesТег объекта) в System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod (IAsyncResult asyncResult) в System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilter.inInWF.Wync.Wc.InInFW.Inc.Win.dll)c__DisplayClass46.b__3f ()