2017-03-17 67 views
-2

目前我正在执行一个登记表,我需要添加出生日期,即当您单击显示日历,努力做到这一点,可以有人用代码通知文本框中,在表单上添加日期选项?

目前使用C#, MVC剃刀,如果有人用模型属性和查看答案将是一件好事..

目前下面是我的代码:

型号

public string DateOfBirth { get; set; } 

查看

​​
+0

你为什么不jQuery的用户有可用现成的插件很多对丰富的UI – user7417866

+0

@ user7417866我该怎么办? –

+0

https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions/using-the-html5-and-jquery-ui-datepicker-popup-calendar-with-aspnet-mvc/using -html5 -jquery-ui-datepicker-popup-calendar-with-aspnet -mvc-part-4 – user7417866

回答

0

这里,这是我们在我们的MVC项目中所做的。

添加了jQuery UI脚本放在CSHTML页面

<script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
@Html.TextBoxFor(model => model.DateOfBirth, new { placeholder = "Select D.O.B", @style = "", @class = "CommonDatePicker form-control", id = "AlternativeTelephoneNo" }) 

的顶部,并在脚本标签或普通的js文件里加入下面的脚本(在整个应用程序使用)

//this date picker allows to select year and month. 
$(document).on('focus', '.CommonDatePicker', null, function() { 
     $(this).datepicker({ dateFormat: 'mm/dd/yy', changeMonth: true, changeYear: true }); 
}); 

更多这方面的信息请参考https://jqueryui.com/datepicker