[英]Passing only Date from controller through DateTime Object. Trying Multiple ways bind Time alongwith
My .cs
file contains this. 我的.cs
文件包含这个。
Model also contains the same datatype
模型还包含相同的datatype
while filling data in form i get the value as 在填写表单中的数据时,我得到的值为
In SQL i've kept datatype as date
and in model it is necessary to keep DateTime. 在SQL中,我将数据类型保留为date
,在模型中,必须保留DateTime。
I tried ParseExact()
, .Date
, etc but everything ultimately turns out along with time. 我尝试了ParseExact()
.Date
等,但最终结果随着时间的推移而变化。
Can anyone please help? 有人可以帮忙吗? I tried many solutions found in this site related to this question but didn't get any help. 我在本网站上尝试了很多与此问题相关的解决方案,但没有得到任何帮助。
thank you in advance. 先感谢您。
Add this to your Model 将其添加到您的模型中
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
and in the .cshtml 并在.cshtml中
@Html.TextBoxFor(m => m.LastPaymentDate, "{0:dd/MM/yyyy}")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.