-1

I only need to apply Culture on single TextBox control in its DataAnotation attribute, not for whole model

Languages https://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx

In MVC5 C#

eg.

[System.ComponentModel.DataAnnotations.DisplayFormat(ApplyFormatInEditMode = true,DataFormatString = "ur-PK")]public string test { get; set; }

But it does not work.

mmushtaq
  • 3,430
  • 7
  • 30
  • 47
zubair Ahmad
  • 121
  • 3
  • 11
  • You property is a `string` and it makes no sense to apply formats to a`string`! What are you trying to do? What is the value of the property and what is the expected output –  Nov 05 '16 at 08:55
  • i am trying to rendar textbox control with URDU language typing support – zubair Ahmad Nov 05 '16 at 08:57
  • That's not what the `DisplayFormatAttribute` is for - its for displaying numeric and `DateTime` properties in a particular format - so a `DateTime` which is today's date could be displayed as `11/5/2016` or `Sat 5 Oct 2016` etc –  Nov 05 '16 at 09:05
  • can you recomend any other datatype – zubair Ahmad Nov 05 '16 at 09:06
  • `DataType` has nothing to do with language typing support. –  Nov 05 '16 at 09:07

1 Answers1

0

If your question is about display your string in specific culture and you don't want to change language of everything (Just this textBox), you can create custom DataAnnotation like that

public class LocalizedDisplayNameAttribute : DisplayNameAttribute
{
    public LocalizedDisplayNameAttribute(string displayNameKey)
        : base(displayNameKey)
    {
    }

    public override string DisplayName
    {
        get
        {
            // Get your string from db 
            // or load it from specific resource file 
            //(as your business) and return string;
        }
    }
}

But if you don't need all this, you can use the default Display and load your sting from Resource files

Ahmed
  • 1,542
  • 2
  • 13
  • 21