Back to Devexpress

Using Extensions in Razor Views

aspnetmvc-9944-common-features-using-extensions-in-razor-views.md

latest3.2 KB
Original Source

Using Extensions in Razor Views

  • Jun 21, 2024
  • 4 minutes to read

This document covers the main aspects of using DevExpress ASP.NET MVC Extensions in Razor Views.

You can declare DevExpress extensions within View pages by using either expression syntax ( @ or @()) or code block syntax ( @{} ). Refer to the Introduction to ASP.NET Web Programming Using the Razor Syntax article to learn more about Razor syntax specifics. The main declaration rules include the following:

  • If expression syntax is used, call the extension’s ExtensionBase.GetHtml method at the end of an extension declaration.

  • If code block syntax is used, call the extension’s ExtensionBase.Render method at the end of an extension declaration.

Different usage cases that relate to the DevExpress MVC extension declaration are listed below.

In View Pages (Without Nesting)

The following declaration types are in effect when you place a DevExpress MVC extension at the top level of a view or a partial view (not nested within the templates of other extensions).

  • Expression syntax

  • Code block syntax

In Razor Page Sections

If a DevExpress MVC extension is used within a View’s named section that is referred to from a layout page (via the RenderSection method, e.g., @RenderSection(“NavBarSection”)), you can define the section in the following manner.

  • Expression syntax

  • Code block syntax

Referring to Partial Views

When a DevExpress MVC extension is defined in a separate partial view (for instance, when the extension works in a callback mode), you can refer to this partial view as demonstrated below.

  • Expression syntax

  • Code block syntax

Defining Extension Settings

Syntactically, when calling the DevExpress HTML helper method within a View, an extension’s settings can be defined in the following two ways.

  • Using a Settings Delegate within a View

  • Passing a Settings Object from a Controller

As the previous code illustrates, after defining settings, it might be required to bind an extension to data. For this purpose, the Bind () method of extension objects can be used. This method allows you to bind an extension to a Model (your business data objects), which is passed to a View from the Controller. See the Data Binding topic to learn more.

Refer to the Extension Sheet topic for a list of currently available DevExpress Extensions for ASP.NET MVC, together with corresponding HTML helper methods, extension and settings classes, and client counterpart objects.

See Also

Get Started