Asp.net mvc DataFormatString=";{0:N}";不在MVC模型上工作

Asp.net mvc DataFormatString=";{0:N}";不在MVC模型上工作,asp.net-mvc,asp.net-core,integer,dataformat,displayformat,Asp.net Mvc,Asp.net Core,Integer,Dataformat,Displayformat,我想在milles上加上点和逗号,表示CurrentCulture函数中“int”类型的数字。我正在尝试使用DataFormtString,但它不起作用。 例如:1234567==>123.456.789 我正在使用MVC,我想在表格、输入等中格式化数字 .Replace()或类似的内容不是解决方案,我希望它在 当前文化 例如: [DisplayName("Test")] [DisplayFormat(ApplyFormatInEditMode = true,

我想在milles上加上点和逗号,表示CurrentCulture函数中“int”类型的数字。我正在尝试使用DataFormtString,但它不起作用。 例如:1234567==>123.456.789

我正在使用MVC,我想在表格、输入等中格式化数字

.Replace()或类似的内容不是解决方案,我希望它在 当前文化

例如:

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

        <span class="text">@Model.Example</span>
        <input asp-for="Example" class="form-control form-control-sm" />
@Model.Example

根据您的描述,我已经在我这边创建了一个测试演示,我发现该值已设置为输入,但由于输入类型的值,它无法显示

我建议您可以将输入类型设置为文本,然后重试

更多详细信息,请参考以下代码:

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

<input asp-for="Example" class="form-control form-control-sm" type="text" />
@Model.Example
结果:


它不起作用了
-会发生什么呢?什么都没有,只显示完整的数字,没有上千点,如果你不使用它,显然是不起作用的。当我尝试时。它得到了
123.456.789,00
。看起来您的问题已经解决了?使用DisplayFor可以,但是是否仍然使用TagHelper?谢谢您的回答!类型必须隐藏,不能是开头的文本。在另一个函数性之后,将显示此输入。我无法理解为什么要隐藏您的类型。如果要隐藏输入,可以将css显示设置为“无”。