MVC4中的DatePicker [英] DatePicker in MVC4
问题描述
我在我的mvc4应用程序中使用@Html.JQueryUI().DatepickerFor
辅助方法.第一次正确显示压光机,但是一旦过帐表格则不显示.谁能告诉我我想念的东西吗?
i am using @Html.JQueryUI().DatepickerFor
helper method in my mvc4 application. It is showing the calender correctly at first time but it is not showing once the form is posted. Can anyone tell me what i am missing in it?
推荐答案
我怀疑您正在使用AJAX提交表单,并且如果提交成功,则您正在刷新内容,因此日期选择器不再绑定到输入字段.因此,在您的AJAX请求的成功回调中,您需要重新绑定它:
I suspect that you are using AJAX to submit the form and in case of successful submission you are refreshing the contents and thus the date picker is no longer bound to the input field. So inside the success callback of your AJAX request you need to rebind it:
success: function(data) {
$('#some_id').html(data);
$('#id_of_your_input_element').datepicker();
}
或者,如果您使用的是Ajax.BeginForm,则可以在AjaxOptions中订阅成功事件:
Or if you are using an Ajax.BeginForm you could subscribe to the Success event in the AjaxOptions:
@using (Ajax.BeginForm(new AjaxOptions { Success = "success", UpdateTargetId = "someId" }))
{
...
}
,然后编写success
回调:
function success(data) {
$('#id_of_your_input_element').datepicker();
}
这篇关于MVC4中的DatePicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!