偷懒想用MVC的模板,结果遇见了日期显示成2012-01-01 00:00这样的问题:
错误代码:@Html.TextBoxFor(model => model.ContractDate.ToString("yyyy-MM-dd"), new { @class = "Wdate", onclick = "WdatePicker()" })
然后系统报错 “模板只能用于字段访问、属性访问、一维数组索引或单参数自定义索引器表达式。”
在网上找了N多帖子终于发现了解决办法:
第一个:@Html.TextBoxFor(model => model.ContractDate, new { @class = "Wdate", Value = Model.ContractDate.ToString("yyyy-MM-dd"), onclick = "WdatePicker()" })
或者: @Html.TextBoxFor(model => model.ContractDate, new { @class = "Wdate", Value = String.Format("{0:d}", Model.ContractDate), onclick = "WdatePicker()" })
http://stackoverflow.com/ 还是比较强大滴