2017-07-26 54 views
0

我试图访问标签助手中的共享资源,但它不会从资源文件返回值,即使我知道它存在,只有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

通过安装NuGet包Microsoft.AspNetCore.Mvc.Localization

解决它