public class MyModel
{
    [Display(ResourceType = typeof(MyModelResourceProvider), Name = "MyProperty")]
    public string MyProperty { get; set; }

    ...
}

public class MyModelResourceProvider
{
   public static string MyProperty
   {
       get 
       {
           return GetLocalizedString("keyinresourcefile"); 
       }
   }
}

The GetLocalizedString takes in the resource key and returns localized string from the XML file. for e.g. it returns "Blah Blah Blah{#12321". Please note that the returned localized string contains characters like curly brace & hash.

I am using this model in the cshtml page as follows.

@Html.TextBoxFor(m => m.MyProperty, new {autocomplete = "off", tabindex = "1"})

I get System.FormatException at the above line. When I wrap the GetLocalizedString("keyinresourcefile") with WebUitility.HtmlDecode the Html.TextBoxFor in cshtml runs without any error.

I know that the curly brace in the localized string is causing this error. But I want to know why does this work when I wrap it in WebUtility.HtmlDecode?

Related posts

Recent Viewed