[英]jQuery UI datepicker not working with asp.net mvc
I am working with ASP.Net MVC with Jquery Date picker. 我正在使用带有Jquery日期选择器的ASP.Net MVC。
here is my model class 这是我的模特班
public class myViewModel
{
public DateTime? FromDate {get;set;}
public DateTime? ToDate {get;set;}
}
here is my View Class 这是我的View Class
@model testApp.myViewModel
@Html.TextBox("FromDate","{0:MM/dd/yyyy}", new { @class = "datepicker" })
@Html.TextBox("ToDate","{0:MM/dd/yyyy}", new { @class = "datepicker" })
and JQuery 和JQuery
<script>
$(function () {
$(".datepicker").datepicker({
changeMonth: true,
changeYear: true
});
});
</script>
Now the issue is whenever my page is load default date does not display in textbox instead "{0:MM/dd/yyyy}" display in both textbox 现在的问题是,无论何时我的页面加载,默认日期都不会显示在文本框中,而是在两个文本框中都显示“ {0:MM / dd / yyyy}”
So how can I display and bind current date value in my FromDate and ToDate textbox? 那么,如何在FromDate和ToDate文本框中显示并绑定当前日期值?
Thanks 谢谢
use this, 用这个,
<script>
$(function () {
$(".datepicker").datepicker({
changeMonth: true,
changeYear: true,
setDate : new Date()
});
});
</script>
Make sure the following using statements are included in your Model 确保模型中包含以下using语句
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
Change Model as follows 更改模型如下
[Display(Name = "Date")]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyy}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> Date { get; set; }
Your JQuery is 您的JQuery是
<script>
$(function () {
$(".datepicker").datepicker({ dateFormat: "MM/dd/yy", changeMonth: true, changeYear: true });
});
</script>
And View Class is 而且View Class是
@Html.TextBoxFor(model => model.FromDate, "{0:MM/dd/yyyy}", new { id = "datepicker" })
@Html.TextBoxFor(model => model.ToFromDate, "{0:MM/dd/yyyy}", new { id = "datepicker" })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.