Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to isolate extension settings into separate helper class and share a single partial view to display multiple extensions

$
0
0
This example is more specific to ASP.NET MVC platform rather than to our extensions. It illustrates two popular techniques which can be used with any extensions (we chose a GridView extension for this example):

1) A separate helper class that holds extension settings. This technique might be useful in numerous scenarios. A couple of examples:

E3898 - How to export GridView data to different rich text formats
E3997 - Scheduler - Lesson 3 - How to Use Scheduler in complex views

In our example we define the most flexible form of extension method in the setting helper class:
[C#]
publicstaticGridViewSettingsCreateGridViewSettings(thisWebViewPageview,GridTypegridType)
[VB.NET]
<System.Runtime.CompilerServices.Extension> _PublicFunction CreateGridViewSettings(ByVal view As WebViewPage, ByVal gridType As GridType) As GridViewSettings
Note that we use the WebViewPage Class (System.Web.Mvc) class as the first parameter here. This allow us to access all the APIs which are available in the regular MVC views. For instance, you can use "view.Html", "view.Url", etc. members to access HtmlHelper, UrlHelper (both of them are illustrated in the source code of this example) and other APIs in convenient manner.

2) A single partial view (GridViewPartial.cshtml / GridViewPartial.vbhtml) is used to display multiple extensions. We pass the "gridType" parameter to the corresponding action method to determine which extension should actually be rendered:
[C#]
@Html.Action("GridViewPartial",new{gridType=GridType.Invoices})
[VB.NET]
@Html.Action("GridViewPartial", NewWith {.gridType = GridType.Invoices})
This parameter value comes up to the extension method in the setting helper class (we use the ViewData dictionary to pass it to the partial view) and here we use it to render specific content.

See Also:
Extension Methods (C# Programming Guide)
Question Comments

Added By: Włodzimierz Oleksiw at: 7/4/2016 9:53:46 AM    And if we have 1000 gridview with different columns ? Create 1000 extansion method for them?
Added By: Alessandro (DevExpress Support) at: 7/4/2016 10:16:59 AM    We will answer this question in the T399467: GridView - Add a hyperlink to template form code ticket. This ticket is currently in our processing queue. Our team will address it as soon as possible.

Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>