Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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# MVC文本框,用于显示日期格式而不是值_C#_Asp.net_Asp.net Mvc 5_Date Format - Fatal编程技术网

C# MVC文本框,用于显示日期格式而不是值

C# MVC文本框,用于显示日期格式而不是值,c#,asp.net,asp.net-mvc-5,date-format,C#,Asp.net,Asp.net Mvc 5,Date Format,我正在处理ASP.NET应用程序,我遇到了日期格式问题。 TextBoxFor显示的是日期格式,而不是日期 区域设置: Culture: Invariant Language (Invariant Country) Enable Client Based Culture: false UI Culture: Invariant Language (Invariant Country) File:

我正在处理ASP.NET应用程序,我遇到了日期格式问题。 TextBoxFor显示的是日期格式,而不是日期

区域设置:

Culture:                       Invariant Language (Invariant Country)
Enable Client Based Culture:   false
UI Culture:                    Invariant Language (Invariant Country)
File:                          Windows-1252
Requests:                      utf-8
Response Headers:              utf-8
Responses:                     utf-8
<div class="form-group">
       <div class="col-md-10">
             @Html.Label("Invoice Date:")
             <div class="fiveSpace"></div>
             @Html.TextBoxFor(model => model.InvoiceDate, "{0:d}", new { type = "date" })
             @Html.ValidationMessageFor(model => model.InvoiceDate)
       </div>
</div>

<div class="form-group">
       <div class="col-md-10">
             @Html.Label("Due Date:")
             <div class="fiveSpace"></div>
             @Html.TextBoxFor(model => model.DueDate, "{0:d}", new { type = "date" })
             @Html.ValidationMessageFor(model => model.DueDate)
       </div>
</div>
[Required(ErrorMessage = "Please select Invoice Date.")]
public DateTime? InvoiceDate { get; set; }
[Required(ErrorMessage = "Please select Due Date.")]
public DateTime? DueDate { get; set; }
英国,日期格式:“yyyy-mm-dd”

.NET全球化-IIS设置:

Culture:                       Invariant Language (Invariant Country)
Enable Client Based Culture:   false
UI Culture:                    Invariant Language (Invariant Country)
File:                          Windows-1252
Requests:                      utf-8
Response Headers:              utf-8
Responses:                     utf-8
<div class="form-group">
       <div class="col-md-10">
             @Html.Label("Invoice Date:")
             <div class="fiveSpace"></div>
             @Html.TextBoxFor(model => model.InvoiceDate, "{0:d}", new { type = "date" })
             @Html.ValidationMessageFor(model => model.InvoiceDate)
       </div>
</div>

<div class="form-group">
       <div class="col-md-10">
             @Html.Label("Due Date:")
             <div class="fiveSpace"></div>
             @Html.TextBoxFor(model => model.DueDate, "{0:d}", new { type = "date" })
             @Html.ValidationMessageFor(model => model.DueDate)
       </div>
</div>
[Required(ErrorMessage = "Please select Invoice Date.")]
public DateTime? InvoiceDate { get; set; }
[Required(ErrorMessage = "Please select Due Date.")]
public DateTime? DueDate { get; set; }
MainView(我尝试了
toSortDateString()
ToString(“d”)
):

和结果:

一旦我尝试编辑日期:

正确的值存储在“值”中,但TextBoxFor显示日期格式。此外,当我将地区设置更改为其他国家/地区时,在主视图中,我始终以“dd/mm/yyyy”格式显示收到的日期,在编辑视图中,日期以“mm/dd/yyyy”格式显示

我试过:

  • web.config
  • 向模型添加
    [DisplayFormat(DataFormatString=“{0:d}]”

问题出在我这边,还是IIS?

带有
type=“date”
TextBoxFor
将其转换为
HTML标记,该标记不支持根据日期自定义日期格式


它可以通过一些第三方JS库来实现,比如or

文本框for
type=“date”
转换为
HTML标记,该标记不支持根据

它可以通过一些第三方JS库来实现,比如or

我已将前面提到的
TextBoxFor
替换为:

@Html.TextBoxFor(model => model.InvoiceDate, new { @type = "date", @Value = Model.InvoiceDate.Value.ToString("yyyy-MM-dd") })
它是有效的。

解决了

我已将前面提到的
TextBoxFor
替换为:

@Html.TextBoxFor(model => model.InvoiceDate, new { @type = "date", @Value = Model.InvoiceDate.Value.ToString("yyyy-MM-dd") })
它是有效的