DataFormatString = "{0:N}" not working on Model MVC

725 views Asked by At

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" />
1

There are 1 answers

2
Brando Zhang On

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