如何在创建和编辑视图中的ASP.NET MVC中应用jQuery DatePicker [英] How to apply jQuery DatePicker in ASP.NET MVC in Create and Edit View

查看:115
本文介绍了如何在创建和编辑视图中的ASP.NET MVC中应用jQuery DatePicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASP.NET MVC 4应用程序,并且在将日期绑定到特定控制器的编辑"视图中的jQuery DatePicker上时遇到困难,该字段具有一个字段为DateTime类型的"PurchaseDate".我已经使用数据注释设置了所有日期格式.但是仍然无法按预期在编辑"模式下工作.我正在使用bootstrap-datepicker.

如果有合适的解决方案,请回复.请参考以下代码:

[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true,DataFormatString ="{0:dd-mm-yyyy}")]
公开的DateTime PurchaseDate {get;放; }


并编辑视图,如下所示:

@ Html.TextBoxFor(model => model.PurchaseDate,新的{@class ="form-control date-picker",value = Model.PurchaseDate.ToString("dd-mm-yyyy")})

我正在应用bootstrap-datepicker,如下所示:


$(''.date-picker'').datepicker({rtl:App.isRTL(),autoclose:true});

I am working on a ASP.NET MVC 4 application and I have difficulty with Binding date to jQuery DatePicker in Edit view of particular controller that having one field say "PurchaseDate" with type DateTime. I have set all date format with Data Annotation. But still it is not working in Edit mode as expected. I am using bootstrap-datepicker.

Please reply if any have proper solution for same. Please refer below code:

[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd-mm-yyyy}")]
public DateTime PurchaseDate { get; set; }


And Edit view as below:

@Html.TextBoxFor(model => model.PurchaseDate, new { @class = "form-control date-picker", value = Model.PurchaseDate.ToString("dd-mm-yyyy") })

And I am applying bootstrap-datepicker as below:


$(''.date-picker'').datepicker({ rtl: App.isRTL(), autoclose: true });

推荐答案

(''. date-picker'').datepicker({rtl:App.isRTL(),autoclose:true});
(''.date-picker'').datepicker({ rtl: App.isRTL(), autoclose: true });



(文档). ready(function(){

(document).ready(function () {


这篇关于如何在创建和编辑视图中的ASP.NET MVC中应用jQuery DatePicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆