1

I want points and commas on milles for numbers type 'int' in function of CurrentCulture. I'm trying to use DataFormtString but its not working. For example: 1234567 ==> 123.456.789

I'm working with MVC and i want to format numbers in tables, inputs, etc.

.Replace() or something like that is not a solution, i want it in function of CurrentCulture.

For example:

    [DisplayName("Test")]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:N}")] // Not working
    public int? Example{ get; set; }

In View:

        <span class="text">@Model.Example</span>
        <input asp-for="Example" class="form-control form-control-sm" />
Arturo
  • 39
  • 10
  • `its not working` - what happens instead? – GSerg Oct 10 '20 at 10:18
  • just nothing, only shows the complete number without points on thousands – Arturo Oct 10 '20 at 10:31
  • 1
    Obviously it's not going to work if you're not using [`@Html.DisplayFor()`](https://stackoverflow.com/questions/16697872/why-is-displayformat-dataformatstring-not-working#comment51351668_16697872). – GSerg Oct 10 '20 at 11:10
  • When I try. It get `123.456.789,00` . Looks like your questions has been resolved? – cuong nguyen manh Oct 10 '20 at 11:41
  • With DisplayFor is ok, but is there anyway using the TagHelper ? – Arturo Oct 10 '20 at 14:15
  • https://stackoverflow.com/q/32671644/11683 – GSerg Oct 10 '20 at 14:45
  • I have also tested the codes, I found the input doesn't show anything but it has already set the value to 123,456,789.00, you could use F12 develop tool to find the actually result. Besides, I suggest you could tell us which culture you have used now. – Brando Zhang Oct 12 '20 at 08:15
  • the culture will be in different languages in function of users, its not set. The problem is that i have to use the tag to show this field value on view and displayformat is not a solution. – Arturo Oct 12 '20 at 18:55

1 Answers1

1

According to your description, I have created a test demo on my side, I found the value has been set to the input, but it couldn't show because of the input type value.

I suggest you could set the input type to text and try again.

More details, you could refer to below codes:

<span class="text">@Model.Example</span>

<input asp-for="Example" class="form-control form-control-sm" type="text" />

Result:

enter image description here

Brando Zhang
  • 22,586
  • 6
  • 37
  • 65
  • Thank you for your response! Type must be hidden, cannot be text at the beginning. After another funcionality this input will be showed – Arturo Oct 13 '20 at 08:23
  • I couldn't understand why your type should be hidden. If you want to hidden the input, you could set the css display to none. – Brando Zhang Oct 13 '20 at 08:38