2017-07-26 10 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

をインストールすることによってそれを解決
関連する問題