Razor Page using Core 2.2 Localization not working

Related searches

I have a .NET Core 2.2 project

I have the following code in my startup

ConfigurationServices method

services.AddLocalization(options => options.ResourcesPath = "Resources");

Configuration method

        var supportedCultures = new[]
            new CultureInfo("en-US"),
            new CultureInfo("es-ES"),
        app.UseRequestLocalization(new RequestLocalizationOptions
            DefaultRequestCulture = new RequestCulture("en-US"),
            // Formatting numbers, dates, etc.
            SupportedCultures = supportedCultures,
            // UI strings that we have localized.
            SupportedUICultures = supportedCultures

I have in my Index Page.csHtml

 @using Microsoft.AspNetCore.Mvc.Localization
 @model IndexModel
 @inject IViewLocalizer Localizer
     ViewData["Title"] = "Error";
 <h3>Welcome to ASP.NET Localization</h3>
 <p>This is Localization</p>

I am using the following methods in my Index.cshtml.cs

    private readonly IStringLocalizer<IndexModel> Localizer;
    public IndexModel(IStringLocalizer<IndexModel> localizer)
        Localizer = localizer;

I have created a Resource File


This currently has a key for Overview.

I load the app and try to change the culture as


But the string does not change as I would expect !

Globalization and localization in ASP.NET Core, This is the first in a series of articles that explores localisation in ASP.NET Core Razor Start by opening the Startup.cs file and adding the following using directives: using System. It is not enabled by default. Amend the� Hi All, I have created a new ASP.NET Core 2.0 Razor Pages application. Everything is working but for some unknown reason, it doesn't show the custom validation messages instead it shows some defaul

Localizations for razor pages should be located in Pages folder. So localizations for Index razor page should be located at


Localisation in ASP.NET Core Razor Pages, pranavkm added the area-mvc label on Dec 26, 2019 Value; does not work either does it with or without the Value command it Localization_Before targets asp.net core 2.2 and Localization_After targets asp.net core 3.1. By Rick Anderson and Ryan Nowak. Razor Pages can make coding page-focused scenarios easier and more productive than using controllers and views. If you're looking for a tutorial that uses the Model-View-Controller approach, see Get started with ASP.NET Core MVC.

With the linked tutorial you are using shared resources so you should not create a sub folder within Resources for Pages etc. but just name each resx file ViewResource.xx.resx.

Issue with globalization asp.net core 3.1 not getting value just key , I have been trying, without success, to create an ASP.NET Core 2.1 Razor web app that uses localization and I keep running into problems� Even developers experienced with Razor C# syntax are more productive using Tag Helpers than writing C# Razor markup. A way to make you more productive and able to produce more robust, reliable, and maintainable code using information only available on the server For example, historically the mantra on updating images was to change the name of

Issues setting up Localization in ASP.NET Core razor App, NET Core contains three technologies: Razor Pages, MVC, and Web API. ASP. NET Core and Blazor use a new way to localize strings. They still use .resx file like every other . If you did not add IViewLocalizer injection into _ViewImports. chtml you have to inject the localizer into each view For example, this won't work. This works fine but creating a Razor Page just to serve JSON doesn't feel right. Razor Pages are intended to generate UI, not act as a data service. You could instead use an existing page and add a named handler to deliver JSON. Let's alter the method in the example page to adopt this approach by renaming OnGet to OnGetCarList:

ASP.NET Core Localization and Internationalization, The page model's associated markup links to the OnGetProfile page handler. Note the On<Verb> prefix of the page handler method name is omitted in the asp-page-handler attribute value. When the method is asynchronous, the Async suffix is omitted, too. <a asp-page="/Attendee" asp-page-handler="Profile" asp-route-attendeeid="12">Attendee Profile</a>

ASP.NET Core 2.0 introduced a new way to build a web site, called Razor Pages.I was interested in the new Razor Pages approach, as I hoped Razor Pages would allow me to code better by following the SOLID principals – and they do.

  • you need to change to language of the browser to make the code work
  • cool, but we want the user to be able to select ? eventually I need a drop down list !
  • then I think you can do reload the page so user will see the change
  • I am changing the url above by adding ?culture=es-ES to the url, but it doesnt change the language
  • Ill check out QueryStringRequestCultureProvider
  • This doesn't answer the question at all