jQuery的日期时间选择器MVC3 [英] jQuery Datetime picker MVC3
本文介绍了jQuery的日期时间选择器MVC3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的模型这一领域
[DataType(DataType.DateTime)]
[Required(ErrorMessage = "Expire is required")]
public DateTime Expire
{
get;
set;
}
在我看来
@Html.EditorFor(model => model.Expire))
@Html.ValidationMessageFor(model => model.Expire)
和创建DATATIME EditorTemplates
and I create DataTime EditorTemplates
@inherits System.Web.Mvc.WebViewPage<System.DateTime>
@Html.TextBox("", (Model.ToShortDateString()), new { @class = "datePicker" })
<script type='text/javascript'>
$(document).ready(function () {
$(".datePicker").datepicker({
// buttonImage: "/content/images/calendar.gif",
// showOn: "both",
// defaultDate: $("#calendar-inline").attr('rel')
showAnim: 'slideDown',
dateFormat: 'dd/mm/yyyy'
});
});
</script>
当我尝试创建新的项目我有这样的错误信息
when i try to Create new Item I have this error message
模型项目传入
字典是空的,但这种
字典需要非空模型
类型的项目'System.DateTime的
The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'
我尝试
Model.HasValue ? Model.Value.ToString("MM/dd/yyyy") : DateTime.Today.ToShortDateString()
但我没有在模型值检查
But i not have in Model Value check
推荐答案
请尝试以下之一:
- 如果该操作是创建一个新的对象传递一个新的实例作为模型,例如
返回查看(新MyObject来())
- 更改
@inherits System.Web.Mvc.WebViewPage&LT;&System.DateTime的GT;
到@inherits System.Web.Mvc.WebViewPage&lt;系统。 ?日期时间&GT;
- If the action is for creating a new object pass a new instance as model, e.g.
return View(new MyObject())
- Change
@inherits System.Web.Mvc.WebViewPage<System.DateTime>
to@inherits System.Web.Mvc.WebViewPage<System.DateTime?>
这篇关于jQuery的日期时间选择器MVC3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文