我在.NET核心写mvc应用程序,我有本地化的问题,我不知道如何将IViewLocalizer添加到我的网格视图。这里是我的代码:.Net核心本地化视图:IViewLocalizer里面Linq表达式
@using NonFactors.Mvc.Grid;
@using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer Localizer
@model IEnumerable<WeegreeEmployeeFormsCore.Models.Employee>
@(Html
.Grid(Model)
.Build(columns =>
{
columns.Add(model => model.Name).Titled(Localizer["Name"]).Sortable(true).Filterable(true);
columns.Add(model => model.Surname).Titled(Localizer["Surname"]).Sortable(true).Filterable(true);
columns.Add(model => model.EmploymentDate).Titled(Localizer["Hired"]).Sortable(true).Filterable(true);
columns.Add(model => model.Country).Titled(Localizer["Country"]).Filterable(true).Sortable(true).Filterable(true);
columns.Add(model => model.EmploymentForm).Titled(Localizer["EmploymentForm"]).Filterable(true);
columns.Add(model => $"<a href=\"{Url.Action("Edit", "Form")}/{model.EmployeeId}\">{Localizer["Edit"]}</a>").Encoded(false);
columns.Add(model => $"<a href=\"{Url.Action("Details", "Form")}/{model.EmployeeId}\">Details</a>").Encoded(false);
})
.Pageable(pager =>
{
pager.PagesToDisplay = 10;
pager.CurrentPage = 1;
pager.RowsPerPage = 10;
})
.Sortable()
.Empty("No data found")
)
当我使用{}
里面表达model.EmployeeId
它的工作原理插入 - 链接工作,但是当我想用定位器来获得题词Edit/Edytuj/змінити etc
。而不是我在我的观点得到了这个: Microsoft.AspNetCore.Mvc.Localization.LocalizedHtmlString
谢谢你,它完美的作品:) – tuchy
在我看来,如果感觉微软一个错误,这是不是在设计上,其实。它不在[文档](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization)中解释 –