Skip to content

Latest commit

 

History

History
55 lines (40 loc) · 2.68 KB

invalid-template-error-when-using-localization.md

File metadata and controls

55 lines (40 loc) · 2.68 KB
title description type page_title slug tags ticketid res_type
'Invalid Template' Error Occurs When Using Localization and Templates
An 'Invalid Template' error occurs when I use nested templates which contain localized strings in ASP.NET Core projects.
troubleshooting
'Invalid Template' Error Is Thrown When Nested Templates and Localization Are Used | Telerik UI for ASP.NET Core
invalid-template-during-localization
invalid, template, error, using, localization, templates
1146274
kb

Environment

Product Progress® Telerik® UI for ASP.NET Core

Description

My UI for ASP .NET Core project uses a Grid with templates and localization of the resource files. The Kendo UI HTML helper generates hash tag symbols, such as И, д, е, н, which cause an error.

Error Message

Uncaught Error: Invalid template:'....'

Cause

ASP.NET Core encodes all Unicode characters except the ones from the BasicLatin range. The encoded characters are similar to . The hash sign (#) in the encoded character representation has a special meaning inside the Kendo UI Templates and breaks their syntax which results in throwing the Invalid template error.

Solution

Widen the character ranges that are treated as safe by the ASP.NET Core encoding mechanism. This approach will prevent the framework from encoding your localized strings.

  1. Open Startup.cs file and locate the ConfigureServices method.

  2. Add the services.AddSingleton(HtmlEncoder.Create(allowedRanges: new[] { UnicodeRanges.BasicLatin, UnicodeRanges.Cyrillic })); line. Inside that code line, replace UnicodeRanges.Cyrillic with the ranges which include all Unicode characters that you use in your localization files. For more information, refer to the relevant table in the Unicode Character Code Charts list. The final result should be similar to the following code snippet:

    public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services
            .AddMvc()
            .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
    
        services.AddSingleton(HtmlEncoder.Create(allowedRanges: new[] { UnicodeRanges.BasicLatin, UnicodeRanges.Cyrillic }));
        services.AddKendo();
    }
    

See Also