Change date display format in View

-1

I have the following field that returns me the date as follows: 09/17/2018 11:52 AM

How to put it within the default pt. I already tried to put .ToString("dd/MM//yyyy") in model.dtProtoclo but it did not work.

<div class="form-group">
    @Html.LabelFor(model => model.Dtprotocolo, htmlAttributes: new { @class = "control-label col-md-4" })
    <div class="col-md-8">
         @Html.TextBoxFor(model => model.Dtprotocolo, new { disabled = "disabled", @readonly = "readonly", @class = "form-control" })
         @Html.ValidationMessageFor(model => model.Dtprotocolo, "", new { @class = "text-danger" })
    </div>
</div>

I did not need to detail it, only the comment below solved my problem

    
asked by anonymous 17.09.2018 / 16:55

1 answer

2

In your ViewModel, add DataAnnotation to the DateTime field:

[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime Dtprotocolo { get; set; }
    
17.09.2018 / 17:01