The dictionary tag helper renders a localized string value from the global dictionary. The value can optionally be wrapped inside a tag.

Usage

Add a tag with the name rx-dictionary to your view. The tag can have the following attributes:

  • key required - the key of the dictionary value that will be rendered.
  • tag-name optional - the HTML tag that the value will be wrapped in. If no tag name is provided, the dictionary value will be rendered without a tag. If the dictionary value is empty, no tag will be rendered even if a tag name is provided.
  • culture-name optional - the .NET culture code of the dictionary value to render. If no culture name is provided, the current request culture (i.e. current page culture) will be used.

Alternatively, you can set rx-dictionary-key on any tag. In that case, the tag contents will be replaced by the dictionary value. The tag will still be rendered even if the dictionary value is empty. With this method, it is not possible to set a different culture, and the current request culture will always be used to render the dictionary value.

Examples

<div>
    <label class="bold"><rx-dictionary key="ImportantLabel" /></label>

    <rx-dictionary key="CloseButton" tag-name="button" />

    <span><rx-dictionary key="AnotherLanguage" culture-name="nl" /></span>

    <p class="intro" rx-dictionary-key="IntroText">This content will be replaced by the dictionary value.<p>
</div>

Remarks

The dictionary value is rendered as a raw value, therefore any HTML in the value will not be encoded.