我必须在同一页面上显示两个结构相同但数据不同的剑道网格。由于是同一网格,只是数据不同,所以我决定将网格置于局部视图中并重新使用。
这是网格的外观。如果看到两个网格,则在控制器中调用相同的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.Add(TKey键,TValue值)
在 Kendo.Mvc.Infrastructure.Implementation.ClassFactory.GetDynamicClass(IEnumerable1 properties) at Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateProjectionNewExpression(IEnumerable
1 propertyValuesExpressions) Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateProjectionInitExpression() 在 Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateAggregateFunctionsProjectionMemberBinding() 在 Kendo.Mvc.Infrastructure.Implementation.Expressions.QueryableAggregatesExpressionBuilder.d__0.MoveNext() 在System.Collections.Generic.List1..ctor(IEnumerable
1集合中)
在 System.Dynamic.Utils.CollectionExtensions.ToReadOnly [T](IEnumerable1 enumerable) at System.Linq.Expressions.Expression.MemberInit(NewExpression newExpression, IEnumerable
1绑定)位于 Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateSelectBodyExpression() 在 Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateSelectExpression() 在 Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilderBase.CreateQuery() 在Kendo.Mvc.Extensions.QueryableExtensions.Aggregate(IQueryable 源,IEnumerable1 aggregateFunctions) at Kendo.Mvc.Extensions.QueryableExtensions.CreateDataSourceResult[TModel,TResult](IQueryable queryable, DataSourceRequest request, ModelStateDictionary modelState, Func
2选择器)位于 Kendo.Mvc.Extensions.QueryableExtensions.ToDataSourceResult(IQueryable 可查询,DataSourceRequest请求,ModelStateDictionary modelState) 在 Kendo.Mvc.Extensions.QueryableExtensions.ToDataSourceResult(IQueryable 可查询,DataSourceRequest请求) Kendo.Mvc.Extensions.QueryableExtensions.ToDataSourceResult(IEnumerable 可枚举,DataSourceRequest请求) KitchenSink.Controllers.VisualsController.ConsolidatedTopNPartialPage_Read(DataSourceRequest 要求,Int32年) p:\ KitchenSink-test \ KitchenSink \ Controllers \ VisualsController.cs:line 101在lambda_method(Closure,ControllerBase,Object [])在 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase 控制器,Object []参数)位于 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 参数) System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation.InvokeSynchronousActionMethod() 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult,ActionInvocation innerInvokeState)位于 System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase
1.End() 在System.Web.Mvc.Async.AsyncResultWrapper.End [TResult](IAsyncResult asyncResult,对象标记) System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d() 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters。<> c__DisplayClass46.b__3f()
答案 0 :(得分:0)
代替执行该方法,您可以尝试其他解决方法。见下文:
.Read(read => read.Action("ConsolidatedTopNPartialPage_Read","Visuals").Data("filters")))
并在您的javascript函数中:
var yr = @ViewBag.year;
function filters()
{
return {
year : yr
};
}