Articles in this section
Category / Section

How to define localized values for .NET MVC Grids?

5 mins read

In the ASP.NET MVC Grid localization, the localized values are provided in the script section and it can be placed in the master page of the application.               

The Grid control allows you to set the localized values for the Grid by using the locale property of the Grid as explained in the following link:

https://www.syncfusion.com/kb/4008/how-to-enable-localization-in-grid

In an application, there may be several Grid controls in several webpages. In that case, instead of defining the localized values for each page, it is better to place the script section of the Grid localized values in the Web Application’s Master page, so that the localized values can be defined commonly for all the Grid controls in the application.

The following code sample demonstrates the same.

ASP

[Site.Master]
<script>
         ej.Grid.locale["de-DE"] = {
             EmptyRecord: "Keine Aufzeichnungen angezeigt",
             GroupDropArea: "Ziehen Sie eine Spaltenüberschrift hier",
             GroupCaptionFormat: "{{:field}}: {{:key}} - {{:count}} {{if count == 1}}Beiträge{{else}}Beiträges{{/if}}",
             UnGroup: "Klicken Sie hier, um die Gruppierung aufheben"   
         };
 
         ej.Pager.locale[“de-DE"] = {
             pagerInfo: "{0} von {1} Seiten ({2} Beiträge)",
             firstPageTooltip: "Zur ersten Seite",
             lastPageTooltip: "Zur letzten Seite",
             nextPageTooltip: "Zur nächsten Seite",
             previousPageTooltip: "Zurück zur letzten Seite",
             nextPagerTooltip: "Zum nächsten Pager",
             previousPagerTooltip: "Zum vorherigen Pager"
         };
    </script>
[Default.aspx]
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Sample._Default" %>
<ej:Grid ID="EmployeesGrid" runat="server" Locale="de-DE" AllowSorting="true" AllowPaging="true" AllowGrouping="true" >
</ej:Grid>

 

MVC

[Layout.cshtml]
<script>
         ej.Grid.locale["de-DE"] = {
             EmptyRecord: "Keine Aufzeichnungen angezeigt",
             GroupDropArea: "Ziehen Sie eine Spaltenüberschrift hier",
             GroupCaptionFormat: "{{:field}}: {{:key}} - {{:count}} {{if count == 1}}Beiträge{{else}}Beiträges{{/if}}",
             UnGroup: "Klicken Sie hier, um die Gruppierung aufheben"   
         };
 
         ej.Pager.locale[“de-DE"] = {
             pagerInfo: "{0} von {1} Seiten ({2} Beiträge)",
             firstPageTooltip: "Zur ersten Seite",
             lastPageTooltip: "Zur letzten Seite",
             nextPageTooltip: "Zur nächsten Seite",
             previousPageTooltip: "Zurück zur letzten Seite",
             nextPagerTooltip: "Zum nächsten Pager",
             previousPagerTooltip: "Zum vorherigen Pager"
         };
    </script> 
[Index.chstml]
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@(Html.EJ().Grid<OrdersView>("FlatGrid")
        .Datasource((IEnumerable<object>)ViewBag.datasource)
        .Locale("de-DE")
        .AllowPaging()
        .AllowGrouping()
 
)

 Conclusion

I hope you enjoyed learning how to define common localized values for multiple Grids.
You can refer to ASP.NET MVC Grid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. 
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!
Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied