This is a migrated thread and some comments may be shown as answers.

[Solved] Implemnet own Extension method for GridBuilder

1 Answer 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Pavel Balas
Top achievements
Rank 1
Pavel Balas asked on 01 Jun 2012, 09:23 AM

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.

 

1 Answer, 1 is accepted

Sort by
0
Pavel Balas
Top achievements
Rank 1
answered on 01 Jun 2012, 09:59 AM

I realize that this is only a debugger problem. When I deleted breakpoint, this error diapers itself. It seems that some watch caused it.

Tags
Grid
Asked by
Pavel Balas
Top achievements
Rank 1
Answers by
Pavel Balas
Top achievements
Rank 1
Share this question
or