Using HTML5 input "date" in MVC 3
HTML5 seems to have new input types like "date" available for many current browser, if I put:
Birthday: <input type="date" id="bday", name="bday"/>
it pops up quite good date picker on Chrome! I could post selected date to server with help of javascript:
updateDate: function() {
var date = $('#bday').val();
var params = { date: date };
$.ajax({
url: '/HelloWorld/updateDateJson',
type: 'POST',
data: JSON.stringify(params),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function (result) { $('#timeServer2').text(result); }
//error: function () { $('#ErrorSelfService').text("Ajax error"); }
});
But then can I use it in a native asp.net mvc3 way using view model and partial view. Some clarification will be appreciated.
Yes you can use it in the same way as it is just posted as a normal string value.
Note though that other browsers may not support this (IE 9 for ex doesnt) so is still recommend just using the jQuery UI date picker control with a jquery mask plugin for MM/dd/yyyy input format (or whatever your supported cultures are for date format)
链接地址: http://www.djcxy.com/p/18658.html上一篇: HTML5中是否有浮点输入类型?
下一篇: 在MVC 3中使用HTML5输入“日期”