Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# chrome中的MVC.net日期格式_C#_Asp.net Mvc_Date - Fatal编程技术网

C# chrome中的MVC.net日期格式

C# chrome中的MVC.net日期格式,c#,asp.net-mvc,date,C#,Asp.net Mvc,Date,我正在构建我的第一个应用程序,但现在我仍停留在Chrome处理日期的方式上(结合IE) 我有一个带有字段的模型: [Display(Name = "AcceptanceDate", ResourceType = typeof(Resources.ModelResources))] [DataType(DataType.Date)] [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0

我正在构建我的第一个应用程序,但现在我仍停留在Chrome处理日期的方式上(结合IE)

我有一个带有字段的模型:

[Display(Name = "AcceptanceDate", ResourceType = typeof(Resources.ModelResources))]
        [DataType(DataType.Date)]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
        public DateTime? AcceptanceDate { get; set; }
我在视图中使用此字段

     @if (Request.UserAgent.ToLower().IndexOf("chrome") > -1)
                            {
 @Html.EditorFor(m => m.AcceptanceDate, ViewBag.disableControls == true ? (object)new { disabled = "disabled", @class = "form-control" } : new { @class = "form-control", @type = "date" })
                            }
                            else
                            {
                                @Html.EditorFor(m => m.AcceptanceDate, ViewBag.disableControls == true ? (object)new { disabled = "disabled", @class = "form-control", @Value = Model.AcceptanceDate.HasValue ? Model.AcceptanceDate.Value.ToString("dd-MM-yyyy") : null } : new { @class = "form-control", @type = "date", @Value = Model.AcceptanceDate.HasValue ? Model.AcceptanceDate.Value.ToString("dd-MM-yyyy") : null })
                            }
并在字段上放置一个日期选择器,代码如下:

<!-- jQueryUI Stylesheet (from CDN) -->
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/smoothness/jquery-ui.min.css" rel="stylesheet" type="text/css" />

<script type='text/javascript'>
    $.datepicker.regional['nl'] = {
        monthNames: [
            'Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni', 'Juli', 'Augustus', 'September', 'Oktober',
            'November', 'December'
        ],
        monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'],
        dayNames: ['Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag', 'Zondag'],
        dayNamesShort: ['Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za', 'Zo'],
        dayNamesMin: ['Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za', 'Zo']
    }

    $.datepicker.setDefaults($.datepicker.regional['nl']);
    $(function () {
        $("input[type='date']").datepicker({
            dateFormat: 'dd-mm-yy',
            showButtonPanel: false
        }).attr('type', 'text');
    });
</script>
@Html.EditorFor(m => m.AcceptanceDate, ViewBag.disableControls == true ? (object)new { disabled = "disabled", @class = "form-control", @Value = Model.AcceptanceDate.HasValue ? Model.AcceptanceDate.Value.ToString("dd-MM-yyyy") : null } : new { @class = "form-control", @type = "date", @Value = Model.AcceptanceDate.HasValue ? Model.AcceptanceDate.Value.ToString("dd-MM-yyyy") : null })
但这导致文本框中没有显示任何值。(该值已发送到视图,但未显示在控件中


请注意。

请更新您的帖子,以包含正在生成的HTML片段(从web浏览器查看源代码)。您的视图代码没有多大意义。首先,在任何情况下,在使用
HtmlHelper
方法时,您都不会设置
属性。其次,您拥有
[DataType](DataType.Date)
意味着
type=“Date”
是通过
EditorFor()
方法自动添加的。第三,如果您使用的是jquery日期选择器,为什么要添加
type=“Date”
?谢谢Stephen,我刚刚清理了一下我的代码(因为旧代码和新代码太乱了)现在它在IE和Chrome下都像一个魅力。