如何在@ Html.DatePickerFor中显示时间? [英] How to not to display the time in the @Html.DatePickerFor?

查看:62
本文介绍了如何在@ Html.DatePickerFor中显示时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我在MVC局部视图中使用以下代码为用户提供选择日期的选项?



@ Html.DatePickerFor(m => m.ReasonData.ReasonModels [0] .Ravi.BeginDate,new {@class =RaviDate})





并使用以下代码来控制格式..



 var builder = new StringBuilder(); 
builder.Append(@< script type =' text / javascript' > $(document).ready(function(){
$('#);
builder.Append( controlId);
builder.Append(@')。datepicker({
showOn:'button',
buttonImage:'Content / Images / Correspondance / calendar.gif',
持续时间:0,
changeMonth:true,
changeYear:true,
dateFormat:'mm / dd / yy'});
});
< / script > );









例如用户选择日期,它将以我想要的正确格式显示为09/23/2014 ....



但如果用户进入下一页并且来回到上一页,它显示日期为9/23/2014 12:00:00 AM,这是我不想要的....



这就是我定义模型属性的方法..



 [必需(ErrorMessage =  必须输入一个失效日期。)] 
[DisplayName( 政策何时失效?)]
[DisplayFormat(DataFormatString = {mm / dd / yy},ApplyFormatInEditMode = true )]
public DateTime? BeginDate { get ; set ; }









请告诉我如何确定日期格式?

解决方案

(document).ready(function(){


('#);
builder.Append(controlId);
builder.Append(@')。datepicker({
showOn:'button',
buttonImage:'Content / Images / Correspondance / calendar.gif' ,
持续时间:0,
changeMonth:true,
changeYear:true,
dateFormat:'mm / dd / yy'});
});
< / script > );









例如当用户选择日期,它将以我想要的正确格式显示为09/23/2014 ....



但如果用户转到下一页并返回在上一页,它显示日期为9/23/2014 12:00:00 AM,这是我不想要的....



这就是我定义模型属性的方法..



 [必需(ErrorMessage =   必须输入一个失效日期。)] 
[DisplayName( 政策何时失效?)]
[DisplayFormat(DataFormatString = {mm / dd / yy},ApplyFormatInEditMode = true )]
public DateTime? BeginDate { get ; set ; }









请告诉我如何确定日期format?


我认为应该可以通过指定日期时间格式来实现,因为HTML时间元素可以检索时间(我还没有尝试过)



< time datetime =YYYY-MM-DDThh:mm:ssTZD> 





请尝试使用此URL

http://stackoverflow.com/questions/3734829/datetime-field-and-html-textboxfor-helper-how-to-use-it-correctly


Hello,

I am using the below code in MVC partial view to give an option for the user to select date?

@Html.DatePickerFor(m => m.ReasonData.ReasonModels[0].Ravi.BeginDate, new { @class = "RaviDate" })


and have the below code to control the format..

var builder = new StringBuilder();
builder.Append(@"<script type='text/javascript'>$(document).ready(function () {
                            $('#");
builder.Append(controlId);
builder.Append(@"').datepicker({
                    showOn: 'button',
                    buttonImage: 'Content/Images/Correspondance/calendar.gif',
                    duration: 0,
                    changeMonth: true,
                    changeYear: true,
                    dateFormat:'mm/dd/yy'});
                });
                </script>");





for example when user selects the date, it would display it in the correct format which I wanted as 09/23/2014....

but if user goes to next page and come back to the previous page, it is displaying the date as 9/23/2014 12:00:00 AM, which is what I don't want....

This is how I have the model property defined..

[Required(ErrorMessage = "A lapse date must be entered.")]
[DisplayName("When did the policy lapse?")]
[DisplayFormat(DataFormatString = "{mm/dd/yy}", ApplyFormatInEditMode = true)]
public DateTime? BeginDate { get; set; }





Please let me know how I can fix the date format?

解决方案

(document).ready(function () {


('#"); builder.Append(controlId); builder.Append(@"').datepicker({ showOn: 'button', buttonImage: 'Content/Images/Correspondance/calendar.gif', duration: 0, changeMonth: true, changeYear: true, dateFormat:'mm/dd/yy'}); }); </script>");





for example when user selects the date, it would display it in the correct format which I wanted as 09/23/2014....

but if user goes to next page and come back to the previous page, it is displaying the date as 9/23/2014 12:00:00 AM, which is what I don't want....

This is how I have the model property defined..

[Required(ErrorMessage = "A lapse date must be entered.")]
[DisplayName("When did the policy lapse?")]
[DisplayFormat(DataFormatString = "{mm/dd/yy}", ApplyFormatInEditMode = true)]
public DateTime? BeginDate { get; set; }





Please let me know how I can fix the date format?


I believe it should be possible by specifying datetime format because HTML time element can retrieve time (i haven't tried it yet)

<time datetime="YYYY-MM-DDThh:mm:ssTZD">



Please try this URL
http://stackoverflow.com/questions/3734829/datetime-field-and-html-textboxfor-helper-how-to-use-it-correctly


这篇关于如何在@ Html.DatePickerFor中显示时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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