【问题标题】:Can I force the MVC-6-Grid to understand the data annotation on the fields我可以强制 MVC-6-Grid 理解字段上的数据注释吗
【发布时间】:2020-09-20 00:53:50
【问题描述】:

我在我的 asp.net MVC 核心 Web 应用程序 3.1 中添加了以下模型类:-

[ModelMetadataType(typeof(Submission_Validation))]
    public partial class Submission
    {


    }

以及以下Submission_Validation类:-

public class Submission_Validation
    {

[DisplayFormat(ApplyFormatInEditMode = true,
DataFormatString = "{0:dd MMMM yyyy hh:mm:ss tt}")]
public DateTime Created { get; set; }
    }

现在如果我使用@Html.DisplayFor(model => model.Created) 显示Created 字段,日期将具有数据注释中指定的正确格式,但如果我在MVC-6-Grid (https://mvc6-grid.azurewebsites.net/) 中呈现值,如下所示:-

@(Html
    .Grid(Model)
    .Build(columns =>
    {
columns.Add(model => model.Created).Titled("Created")
})
    .Using(GridFilterMode.Header)
    .Empty("No data found")
    .Filterable()
    .Sortable()
    .Pageable(pager =>
    {

        pager.RowsPerPage = 250;
    })

日期将忽略指定的数据注释。知道如何解决这个问题吗?

【问题讨论】:

    标签: asp.net-core asp.net-core-mvc webgrid


    【解决方案1】:

    您可以在 Grid 中对其进行格式化:

    columns.Add(model => model.Created).Titled("Created").Formatted("{0:dd MMMM yyyy hh:mm:ss tt}");
    

    【讨论】:

      猜你喜欢
      • 2020-12-15
      • 2017-06-19
      • 2017-10-01
      • 2011-02-28
      • 2019-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多