我用两个 kendo datepicker 制作自定义 mvc 控件,以在部分视图中显示(gregi 和 hijri)日期,如果我更改任何一个的日期,它会将另一个更改为等效日期
导致剑道限制来处理回历日历我进行了一些修改以显示正确的日期我使用文化并将最大日期设置为回历至 29/12/1600
如果我将值(DateTime.Now)设置为回历日历,一切都很好
但我希望它显示空值和用户选择值但如果我删除值并且当用户打开日历时年份显示为 1600 我想显示 1435 并保持值空值
她是我的密码
Controller
public class UserControl_GHDate
{
public DateTime? GregiDate { get; set; }
[Column(TypeName = "DateTime2")]
public DateTime? HijriDate
{
get
{
if (GregiDate==null)
{
return null;//DateTime.Now;
}
else
{
return GregiDate;
}
}
set { }
}
}
Razor
@model MVC_ERP.Models.UserControl_GHDate
<script src="@Url.Content("~/Scripts/jquery.globalize/globalize.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.globalize/cultures/globalize.culture.ar-SA.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.globalize/cultures/globalize.culture.en-US.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/kendo/cultures/kendo.culture.ar-SA.min.js")"></script>
@Html.Kendo().DatePickerFor(model => model.GregiDate).Format("dd/MM/yyyy").Culture("en-US").HtmlAttributes(new { @class = "kendo", style = "width:49%; max-width:280px" }).Events(e => e.Change("GregiChange"))
@Html.Kendo().DatePickerFor(model => model.HijriDate).Value(DateTime.Now).Footer(false).Max("12/29/1600").Culture("ar-SA").Min(new DateTime(1300, 1, 1)).Format("dd/MM/yyyy").HtmlAttributes(new { @class = "kendo", style = "width:49%; max-width:280px" }).Events(e => e.Change("HijriChange"))
<script>
kendo.cultures["ar-SA"].calendars.standard.firstDay =5;
//kendo.cultures["ar-SA"].calendars.standard.months.namesAbbr[0] = "bbb"; //change name of month
kendo.cultures["ar-SA"].calendars.standard.days.namesShort[0] = "";
kendo.cultures["ar-SA"].calendars.standard.days.namesShort[1] = "";
kendo.cultures["ar-SA"].calendars.standard.days.namesShort[2] = "";
kendo.cultures["ar-SA"].calendars.standard.days.namesShort[3] = "";
kendo.cultures["ar-SA"].calendars.standard.days.namesShort[4] = "";
kendo.cultures["ar-SA"].calendars.standard.days.namesShort[5] = "";
kendo.cultures["ar-SA"].calendars.standard.days.namesShort[6] = "";
function GregiChange(e) {
//alert(this.Name())
var GregId = this.element.prop("id");
var arr = GregId.split('_');
var HijId = arr[0] + '_HijriDate';
if ($('#' + GregId).data('kendoDatePicker').value() == null)
{
$('#' + HijId).data('kendoDatePicker').value(null)
return
}
var d = new Date($('#' + GregId).data('kendoDatePicker').value())
//d.setMonth(d.getMonth() + 1);
var j = d.toLocaleDateString("en-US")
//var z = Globalize.cultures["ar-SA"].calendars.standard.convert.toGregorian("1434", "02", "11");
var z = Globalize.cultures["ar-SA"].calendars.standard.convert.fromGregorian(d);
var y = z.toString()
var arrD = y.split(',');
var year = arrD[0]
var month =(arrD[1]==0?1:(eval(arrD[1])+1))
var day = arrD[2]
var dat = day + '/' + month + '/' + year
$('#' + HijId).data('kendoDatePicker').value(dat)
}
function HijriChange() {
var HijId = this.element.prop("id");
var arr = HijId.split('_');
var GregId = arr[0] + '_GregiDate';
if ($('#' + HijId).data('kendoDatePicker').value() == null) {
$('#' + GregId).data('kendoDatePicker').value(null)
return
}
var d = new Date($('#' + HijId).data('kendoDatePicker').value())
var HD = d.getDate() + '/' + (d.getMonth()+1) + '/' + d.getFullYear();
HDMY= d.getDate() + '/' + (d.getMonth()+1)
if (d.getDate() == 31 || HDMY == '30/12' || HDMY == '30/10' || HDMY == '30/8' || HDMY == '30/6' || HDMY == '30/4' || HDMY == '30/2')
{
alert(HD + ' not valid hijri date')
return;
}
var z = Globalize.cultures["ar-SA"].calendars.standard.convert.toGregorian(d.getFullYear(), (d.getMonth() + 1), d.getDate());
var u = new Date(z)
var year = u.getFullYear();
var month = (u.getMonth() == 0 ? 12 : u.getMonth());
var day = u.getDate()+1;
var dat = day+ '/' + month+ '/' + year;
$('#' + GregId).data('kendoDatePicker').value(dat)
}
$(".k-datepicker input").val('');
</script>
谢谢