gpt4 book ai didi

asp.net-mvc - asp mvc EditorFor DateTime 不显示

转载 作者:行者123 更新时间:2023-12-01 23:12:42 25 4
gpt4 key购买 nike

我正在尝试使用以下内容显示从我的 razor 文件中的数据库检索的日期时间字段:

 @Html.EditorFor(model => model.RequestDate);

我 100% 确定 RequestDate 不为空,因为我检查了 View 中传递的模型,它是数据库中的日期。但是,日期时间文本框仍显示“mm/dd/yyyy”。不知道为什么不显示日期。有任何想法吗?谢谢。

这是我的模型:

      [Display(Name = "Time")]
[DataType(DataType.Date)]
public DateTime RequestDate { get; set; }

编辑:

   [HttpGet]
public ActionResult DispatchResponseIndex()
{
DispatchResponseModel model = new DispatchResponseModel();


//if the users session id isnt null then we know they have data related to this form
object UserID = Session["TestID"];
if (UserID == null)
{
return View(model); //default view
}
else
{
UserID = Session["TestID"];
}

LoadDB(model, (Guid)UserID);
//looking at the model here the RequestDate has a valid date of //{5/24/2013 12:00:00 AM}

return View(model);
}

编辑2:

如果我使用 @Html.TextBox("asdasd",Model.RequestDate);然后它将以字符串格式显示保存的日期,但我需要使用文本框的内置日期编辑器。

最佳答案

这似乎确实引起了很多困惑,而且让我很恼火!

如果您使用DataType.Date你需要这样设置:

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]

Chrome's date picker uses the local computer's short date format.甚至设置 lang标签被忽略;这是使用 Chrome 和 <html lang="en-GB"> 的示例:

enter image description here

Chrome 的日期选择器还使用本地计算机的区域设置。页面加载时,将填充日期(如果设置)并且用户可以选择新日期:

enter image description here

注意:如果您更改计算机的区域设置,则必须完全重新启动 Chrome 才能看到区域设置的更改。

关于asp.net-mvc - asp mvc EditorFor DateTime 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16843411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com