[英]Form don't accept DateTime format
Need some help here. 在这里需要一些帮助。 I have the standard edit form the default visual studio application, and when I use the form to edit some DB row, in the datetime it shows me a date like "01-01-0001 00:00:00", and to save the edit i have to change the date to "01/01/0001 00:00:00". 我有默认的Visual Studio应用程序的标准编辑表单,当我使用该表单编辑一些数据库行时,它在日期时间中向我显示了一个日期,例如“ 01-01-0001 00:00:00”,并保存了编辑我必须将日期更改为“ 01/01/0001 00:00:00”。 Its boring, and as it is the date bringed by mvc itself, it should work if I don't touch it right? 它很无聊,因为它是mvc本身带来的日期,如果我触摸不正确,它应该可以工作? My code is the follow: 我的代码如下:
Model 模型
public class Result
{
[Display(Name = "ID")]
public Int32 Id { get; set; }
[Display(Name = "Data/Hora")]
public DateTime Datahora { get; set; }
}
View (where the form is) 视图(窗体所在的位置)
@model ApdlModel.Entities.Resultado
@{
ViewBag.Title = "Edit";
}
<h2></h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Editar Resultado</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Id)
<div class="form-group">
@Html.LabelFor(model => model.Datahora, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Datahora, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Guardar" class="btn btn-default" />
</div>
</div>
</div>
}
Basically, when the mvc gets the value from the BD, it brings the "01/01/0001 00:00:00" format, but when I try to save in that format it dont allow me. 基本上,当mvc从BD获取值时,它将带来“ 01/01/0001 00:00:00”格式,但是当我尝试以该格式保存时,它不允许我使用。 Why? 为什么? What I am doing wrong? 我做错了什么?
Maybe the problem is because your date is not nullable? 也许问题是因为您的日期不可为空? If it is not nullable you should consider setting default value. 如果不能为空,则应考虑设置默认值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.