Change date display format in View

Asked

Viewed 109 times

-1

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

How to put it inside the standard en. I have tried to put the .ToString("dd/MM//yyyy") in the model.dtProtoclo but it didn’t 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, only the comment below solved my problem

1 answer

2


In your Viewmodel, add a DataAnnotation to the country DateTime:

[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime Dtprotocolo { get; set; }
  • I put this code there, went to do an add-Migration on it did not make any impact. Is that right? P.S. I put in the protocol model

  • Igonre, just adding the display format code solved my problem. Thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.