I'm trying to have a create a date format that displays the MM/DD/YYYY and time. So basically it's I'm trying to display 11/17/2020 9:36AM but my code ends up displaying mm/dd/yyyy --:-- -- when I use the date format [DisplayFormat(DataFormatString = "{0:g}", ApplyFormatInEditMode = true)] within my model. I want to remove the seconds off the date format
When I go to check on dev tools it says The specified value "11/17/2020 9:36 AM" does not conform to the required format. The format is "yyyy-MM-ddThh:mm" followed by optional ":ss" or ":ss.SSS". I don't know if there's something wrong with my display format in my model or if there a problem within my razor. If it's neither then what could be the problem and what is the solution?
Model
[Display(Name = "Advocate Time Called")]
[DisplayFormat(DataFormatString = "{0:g}", ApplyFormatInEditMode = true)]
public DateTime? AdvocateTimeCalled { get; set; }
View
<div class="row">
<div class="col form-group">
<p class="card-text m-2">
@Html.LabelFor(model => model.AdvocateTimeCalled)
</p>
@Html.EditorFor(model => model.AdvocateTimeCalled, new { HtmlAttributes = new { @class = "form-control"} })
@Html.ValidationMessageFor(model => model.AdvocateTimeCalled, "", new { @class = "text-danger" })
</div>
</div>
question from:
https://stackoverflow.com/questions/65878984/date-format-from-model-is-not-working-correctly-and-is-displaying-seconds 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…