@Html.TextBoxFor throws System.FormatException when a localized string contains curly braces
public class MyModel { [Display(ResourceType = typeof(MyModelResourceProvider), Name="MyProperty")] public string MyProperty { get; set; } ... } public class MyModelResourceProvider { public static string MyProperty { return GetLocalizedString("stringresourcekey"); } }
GetLocalizedString gets the localized string using stringresourcekey . A localized string can contain characters such as braces, hashes, apostrophes, etc.
My cshtml uses MyProperty as follows.
@Html.TextBoxFor(model => model.MyProperty, new { autocomplete = "off" })
When I run the asp.net mvc application in Visual Studio, this line System.FormatException . I know this is due to curly braces. But where and how can I avoid this? If I try to escape by replacing curly braces with double curly braces in GetLocalizedString , then Html will make double curly braces instead of single ones.
Update 1
I want that since I avoid the curly brace with double curly braces in the GetLocalizedString method (i.e. in C #), I want to display a single curly brace instead of double curly braces in HTML.
source share