我试图在Tag Helper中访问共享资源,但它不会从资源文件中返回值,即使我知道它存在,只有ResourceNotFound。我使用IHtmlLocalizer访问我的一些视图中的共享资源,它工作正常,所以一切都应该正确配置。
标记助手:
[HtmlTargetElement("lc:buy-button", Attributes = "product", TagStructure = TagStructure.WithoutEndTag)]
public class BuyButtonTagHelper : BaseTagHelper
{
private readonly IStringLocalizer<SharedResources> _localizer;
public BuyButtonTagHelper(AppHelper app, IStringLocalizer<SharedResources> localizer) : base(app)
{
_localizer = localizer;
}
public override void Process(TagHelperContext context, TagHelperOutput output)
{
.........
base.Process(context, output);
}
private string ProcessHtml(string html)
{
string result = html.Replace("{?productId?}", this.Product.ToString());
result = result.Replace("{?subscribeText?}", _localizer["SubscribeButtonText"].Value);
return result;
}
[HtmlAttributeName("product")]
public int Product { get; set; } = -1;
}
答案 0 :(得分:0)
通过安装nuget软件包解决它 Microsoft.AspNetCore.Mvc.Localization