使用jQuery日期选择器从ASP MVC @ Html.TextBoxFor控制时间删除 [英] Remove time from ASP MVC @Html.TextBoxFor Control using jQuery datepicker
问题描述
我如何prevent展示了使用jQuery当时间 .datepicker()
?下面是该模型的两个属性部(拍摄日期和到期日期)
[DisplayFormat(ApplyFormatInEditMode = TRUE,DataFormatString ={0:D})]
[显示名称(到期日)]
公共字符串到期日期{搞定;组; } [DisplayFormat(ApplyFormatInEditMode = TRUE,DataFormatString ={0:D})]
[显示名称(拍摄日期)]
公共字符串DateTaken {搞定;组; }
本上使用我的工作视图中的 @ Html.EditorFor
控制工作正常。然而,当我改变控制从这个:
@ Html.EditorFor(型号=> model.DateTaken)
这样:
@ Html.TextBoxFor(M = GT; m.DateTaken,新{ID =dtkn})
为了得到这个工作(标签,控制有日期选择器
适用于它):
<脚本>
$(函数(){
$(#dtkn」)日期选择器('的setDate')。
$(#EXP)日期选择器('的setDate')。
}); $ .datepicker.setDefaults({
buttonImageOnly:真实,
按钮画面:'<%= Url.Content(〜/内容/图片/ magnify.gif)%>,
defaultDate:-1,
gotoCurrent:真实,
prevText:<< preV,
nextText:下一步>>中
});
< / SCRIPT>
突然开始时展现出来。有什么建议么?
修改
我曾尝试以下格式,没有将工作:
$(#dtkn」)日期选择器({DATEFORMAT:'DD-MM-YY'})VAL();
$(#dtkn」)日期选择器({DATEFORMAT:'YY-MM-DD'});
$(#dtkn」)日期选择器('GETDATE')格式('YYYYMMDD')。
和这样的:
$(#dtkn」)日期选择器('GETDATE')日期选择器('DD / MM / YY')。
$('#dtkn')日期选择器('选项',{日期格式:倒是MM Y'});
下面是我看到了Chrome的调试控制台中的错误:
未捕获类型错误:无法调用空的方法日期选择器
通过使用 @ Html.TextBox
,而不是 @ Html.TextBoxFor
我能找到工作过载。
@ Html.TextBox(DateTaken,Model.DateTaken.ToString(MM / DD / YYYY),新{ID =dtkn})
How do I prevent the time from showing up when using the jQuery .datepicker()
? Below is the section of the model for the two attributes (date taken and expiration date)
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
[DisplayName("Expiration Date")]
public string ExpirationDate { get; set; }
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
[DisplayName("Date Taken")]
public string DateTaken { get; set; }
This works fine using the @Html.EditorFor
control on the view I'm working on. However, when I change that control from this:
@Html.EditorFor(model => model.DateTaken)
to this:
@Html.TextBoxFor(m => m.DateTaken, new { id = "dtkn" })
in order to get this to work (label which control has the datepicker
applied to it):
<script>
$(function () {
$("#dtkn").datepicker('setDate');
$("#exp").datepicker('setDate');
});
$.datepicker.setDefaults({
buttonImageOnly: true,
buttonImage: '<%=Url.Content("~/Content/images/magnify.gif") %>',
defaultDate: -1,
gotoCurrent: true,
prevText: "<< Prev",
nextText: "Next >>"
});
</script>
suddenly the time begins to show up. Any suggestions?
EDIT
I have tried the following formats and none will work:
$("#dtkn").datepicker({ dateFormat: 'dd-mm-yy' }).val();
$("#dtkn").datepicker({ dateFormat: 'yy-mm-dd' });
$("#dtkn").datepicker('getDate').format('yyyyMMdd');
and this:
$("#dtkn").datepicker('getDate').datepicker('dd/mm/yy');
$('#dtkn').datepicker('option', { dateFormat: 'd MM y' });
Here is the error I'm seeing the Chrome debugging console:
Uncaught TypeError: Cannot call method 'datepicker' of null
By using @Html.TextBox
as opposed to @Html.TextBoxFor
I was able to find an overload that works.
@Html.TextBox("DateTaken", Model.DateTaken.ToString("MM/dd/yyyy"), new { id = "dtkn" })
这篇关于使用jQuery日期选择器从ASP MVC @ Html.TextBoxFor控制时间删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!