I have a model to write a time used in a task:
public TarefaHoraPendente()
{
HorasAcumuladas = new TimeSpan(0, 0, 0);
Pausada = false;
}
public int ID { get; set; }
[Required(ErrorMessage = "Este campo é obrigatório")]
[StringLength(10, ErrorMessage = "Qtde. Máx.: 10 caracteres")]
public string Identificador { get; set; }
[Required, DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime Data { get; set; }
[Required, DataType(DataType.Time)]
public DateTime HoraInicial { get; set; }
[DataType(DataType.Time)]
public DateTime HoraReinicio { get; set; }
public TimeSpan HorasAcumuladas { get; set; }
public bool Pausada { get; set; }
}
When I create a new entity of this model some values are already filled by the Controller:
public ActionResult Create()
{
DateTime hoje = new ObtendoDataeHoraLocal();
TarefaHoraPendente tarefaHora = new TarefaHoraPendente();
tarefaHora.Data = hoje;
tarefaHora.HoraInicial = hoje;
tarefaHora.HoraReinicio = hoje;
return View(tarefaHora);
}
So everyone has the same information, for example: {07/04/2017 10:20:43} with Date, time, minute and SECONDS.
Go to View:
@model Models.Auxiliares.TarefaHoraPendente
@{
ViewBag.Title = "Projeto";
}
<h2>Iniciar marcação de horas</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Data)
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Data)
</dt>
<dd>
@Model.Data.ToString("dd/MM/yyyy")
</dd>
</dl>
<div class="form-group">
@Html.LabelFor(model => model.Identificador, "Identif.(Máx.10 caract.)", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Identificador, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Identificador, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.HoraInicial, "Hora inicial", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.HoraInicial, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.HoraInicial, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Iniciar contagem" class="btn btn-default" />
</div>
</div>
</div>
}
And in View, the StartTime field no longer shows the seconds and I see nothing that indicates this truncation.
Someone knows what I'm doing wrong.