我在.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)中解釋 –