我的.cs文件包含此文件。

c# - 通过DateTime对象仅从 Controller 传递Date。尝试多种方式绑定(bind)时间-LMLPHP

模型也包含相同的datatype

当以表格形式填充数据时,我得到的值为

c# - 通过DateTime对象仅从 Controller 传递Date。尝试多种方式绑定(bind)时间-LMLPHP

在SQL中,我将数据类型保留为date,在模型中,必须保留DateTime。

我尝试了ParseExact().Date等,但最终所有内容都随着时间而变化。

c# - 通过DateTime对象仅从 Controller 传递Date。尝试多种方式绑定(bind)时间-LMLPHP

谁能帮忙吗?
我尝试了在此站点中找到的与此问题相关的许多解决方案,但没有得到任何帮助。

先感谢您。

最佳答案

将此添加到您的模型

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]


并在.cshtml中

@Html.TextBoxFor(m => m.LastPaymentDate, "{0:dd/MM/yyyy}")

关于c# - 通过DateTime对象仅从 Controller 传递Date。尝试多种方式绑定(bind)时间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48002507/

10-08 23:42