ASP.Net MVC C#Chrome在编辑模式下不显示日期 [英] ASP.Net MVC C# Chrome not showing date in edit mode

查看:241
本文介绍了ASP.Net MVC C#Chrome在编辑模式下不显示日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google Chrome V28作为我的浏览器 - 并且在我的模型中存在DataAnnotations问题,这会强制Chrome在我的视图中呈现数据时间类型时使用它自己的建立日历。



我的模型是:

  public class ObScore 
{
public int ObScoreId {get;组; }
$ b $
...
[DisplayFormat(DataFormatString ={0:dd MMMM yyyy},ApplyFormatInEditMode = true)]
[Display( Name =Date)]
[DataType(DataType.Date)]
public DateTime Date {get;组; }
...
...
}

绝对是模型中的数据:



...但在编辑模式下显示时,Chrome显示:



这是Chrome中的一个已知错误,并且我可以在代码中执行任何操作来强制日期进入表单吗?



谢谢,Mark

解决方案

尝试删除 [DataType(DataType.Date)] 因为我相信这会创建< input type =date/> 。如果你这样做,你最终会得到一个< input type =text/> 你可以附加jQuery日期选择器。



在不同的浏览器中尝试 w3schools:输入类型日期以看看其中的差别。



编辑:

过去我使用以下在我的 View 中使用jQuery date-picker工作(如果您有兴趣使用它)。



@ Html.TextBoxFor(model => model.DateOfBirth,@{0:yyyy\ / MM\ / dd},new {@class =datepicker})


I am using Google Chrome V28 as my browser - and have a problem with the DataAnnotations on my model, which force Chrome to use it's own inbuild calendar when rendering a datatime type in my view.

My model is:

public class ObScore
{
    public int ObScoreId { get; set; }

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

There is definitely data in the model:

...but when displaying in Edit mode, Chrome shows:

Is this a known bug in Chrome, and is there anything I can do in my code, to force the date into the form?

Thanks, Mark

解决方案

Try removing [DataType(DataType.Date)] because I believe this creates <input type="date" />. If you do that you'll end up with a <input type="text" /> to which you can attach jQuery date-picker.

Try w3schools: input type date in different browsers to see the difference.

Edit:

In the past I used the following in my View to make this work with jQuery date-picker (if you're interested in using it).

@Html.TextBoxFor(model => model.DateOfBirth, @"{0:yyyy\/MM\/dd}", new { @class = "datepicker" })

这篇关于ASP.Net MVC C#Chrome在编辑模式下不显示日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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