Reputation: 1187
I'm trying to add Localization to my ASP.NET MVC application. However, I'm already failing at including the necessary packages. I'm fairly certain that my application is using Views, and I'm about 50% sure that it's using Razor pages. At least the Razor pages syntax works, except in this case.
I'm following this official Microsoft tutorial and this one. Both appear to use about the same code that I'm using. I might be missing a crucial package, though.
Here's part of my _Layout.cshtml
.
@using Microsoft.AspNetCore.Mvc.Localization
@using System.Threading.Tasks
@inject IViewLocalizer Localizer
<!DOCTYPE html>
The first two @using
lines work flawlessly. The fourth line throws an error and the page shows an error in the browser.
CS0103: The name 'inject' does not exist in the current context
Upvotes: 1
Views: 4112
Reputation: 1187
So it turns out I was missing the .NET Core development environment. You can install it via the Visual Studio installer.
Note that this will not necessarily turn your existing ASP.NET application into a Core application.
Regular old AST.NET MVC localization appears to be quite easy. (Archive link just in case)
@Resources.<Name of your file>.<Name of the resource line>
Example:
<h3>@Resources.Global.AppName</h3>
Upvotes: 4