Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#模型的数据注释';s道具未格式化?-双字_C#_.net_Asp.net Core_Data Annotations - Fatal编程技术网

C#模型的数据注释';s道具未格式化?-双字

C#模型的数据注释';s道具未格式化?-双字,c#,.net,asp.net-core,data-annotations,C#,.net,Asp.net Core,Data Annotations,我有一个类的数据注释[DisplayFormat(DataFormatString=“{0:n2}”,ApplyFormatInEditMode=true)]根本没有格式。我已经包含了使用System.ComponentModel.DataAnnotations的也在我的课堂上 下面是我的班级: public class StepTwo : IEnumerable { public int Id { get; set; } public strin

我有一个类的数据注释
[DisplayFormat(DataFormatString=“{0:n2}”,ApplyFormatInEditMode=true)]
根本没有格式。我已经包含了使用System.ComponentModel.DataAnnotations的
也在我的课堂上

下面是我的班级:

    public class StepTwo : IEnumerable
    {
        public int Id { get; set; }
        public string Party { get; set; }
        public string Currency { get; set; }

        [DisplayFormat(DataFormatString = "{0:n2}", ApplyFormatInEditMode = true)]
        public double? Amount { get; set; }

        public IEnumerator GetEnumerator()
        {
            return GetEnumerator();
        }
    }
现在,当我在程序中使用这个类时,数字没有格式化?我知道我可以在Razor页面中完成这项工作,但使用数据注释的全部意义在于,您不必在任何地方都这样做

我尝试了
[DisplayFormat(ApplyFormatInEditMode=true),DataFormatString=“{0:n2}”]
,但它没有改变任何东西

我不知道为什么这个没有格式化?我错过了什么

谢谢你的帮助,谢谢你的建议

我已将剃须刀页面包括在下面:

<table class="table table-hover">
    @foreach (var cus in Model.SSTwo)
    {
        <tr>
            <td>@cus.Id</td>
            <td>@cus.Currency</td>
            <td>@cus.Party</td>
            <td>@cus.Amount</td>

        </tr>
    }
</table>

@foreach(Model.SSTwo中的var cus)
{
@客户识别号
@货币
@顾客聚会
@计算金额
}

您已将ApplyFormatInEditMode设置为true,以便格式化仅在编辑模式下工作,只需将其删除即可查看格式化工作。

尝试以下操作:

<table class="table table-hover">
@foreach (var cus in Model.SSTwo)
{
    <tr>
        <td>@cus.Id</td>
        <td>@cus.Currency</td>
        <td>@cus.Party</td>
        <td>@Html.DisplayFor(modelitem=>cus.Amount)</td>
    </tr>
}
</table>

@foreach(Model.SSTwo中的var cus)
{
@客户识别号
@货币
@顾客聚会
@DisplayFor(modelitem=>cus.Amount)
}

请包括您的剃须刀/视图code@jcruz,我把它加进去了