MVC DateTime 字段 EditTime 必须是日期模板只能用于字段访问、属性访问、一维数组索引或单参数自定义索引器表达式...

ASP.NET MVC 中model含有DateTime类型的字段

更新字段时提示:字段 EditTime必须是日期,、

但是明明填入的是日期还是给出这个提示,

看有的博客说那是因为日期形式错了,如果填入20130104那是不能通过了,填入01/04/2013就行了

我是用的MVC5,手动输入“01/04/2013”这样的格式也是失败的,但是改成“2016-07-13”这样的就可以了

从Google找到了几种解决方法,记录一下:(原文地址http://stackoverflow.com/questions/1961114/date-only-from-textboxfor

方法一:

  I'm having trouble displaying the only date part of a DateTime into a textbox using TextBoxFor<,>(expression, htmlAttributes).

  The model is based on Linq2SQL, field is a DateTime on SQL and in the Entity model.

<%= Html.TextBoxFor(model => model.dtArrivalDate, String.Format("{0:dd/MM/yyyy}", Model.dtArrivalDate))%>

方法二:

  

[DisplayName("Start Date")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime StartDate { get; set; }
<%=Html.EditorFor(m => m.StartDate) %>

方法三:

<%= Html.TextBoxFor(model => model.EndDate, new { @class = "jquery_datepicker", @Value = Model.EndDate.ToString("dd.MM.yyyy") })%>

 

转载于:https://www.cnblogs.com/dansediao/p/5669741.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值