HI all,
Is it possible to create own extension for MVC Grid? I tried simple code
public static GridBuilder<T> RevereseColumns<T>(this GridBuilder<T> builder) where T : class
{
var grid = builder.ToComponent();
grid.Columns.Reverse();
return builder;
}
but this ends with error:
An item with the same key has already been added.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: An item with the same key has already been added.
Source Error:
|
Line 790:@(Html.Telerik().Grid(Model.InternalContractList) Line 791:.Name("gridContractList" + Model.CustomContractStatus) Line 792:.DataKeys(r => r.Add(o => o.ContractId)) |
Source File: c:\Source Code\essox - akvizice\dev\source\ness.adis.web\Areas\CashLoan\Views\InternalGrid\InternalContractList.cshtml Line: 790
Stack Trace:
|
[ArgumentException: An item with the same key has already been added.] System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +12679472 Telerik.Web.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer) in f:\114\Griffin\Trunk Full\Sources\Source\Telerik.Web.Mvc\UI\Grid\Grid.cs:888 Telerik.Web.Mvc.UI.ViewComponentBase.ToHtmlString() in f:\114\Griffin\Trunk Full\Sources\Source\Telerik.Web.Mvc\UI\ViewComponentBase.cs:216 Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.ToHtmlString() in f:\114\Griffin\Trunk Full\Sources\Source\Telerik.Web.Mvc\UI\ViewComponentBuilderBase.cs:154 Telerik.Web.Mvc.{Dynamic}.GridBuilder`1[[Ness.Adis.Business.Core.Common.Dto.Contract.InternalContract, Ness.Adis.Business.Core.Common, Version=1.0.0.0\, Culture=neutral\, PublicKeyToken=null\]\].IHtmlString.ToHtmlString() +40 System.Web.WebPages.WebPageExecutingBase.WriteTo(TextWriter writer, Object content) +58 |
I simplify example to and the error is the same.
public static GridBuilder<T> RevereseColumns<T>(this GridBuilder<T> builder) where T : class
{
return builder;
}
It seems than when I do not change any builder option, column are added twice. How I can create own extension for Grid?
Thank you.