Datapicker with @ Html.EditorFor

0

I have the following model

    [DisplayName("Data Inicial Contrato")]
    [Required]
    [DataType(DataType.Date)]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
    public DateTime DataInicialContrato { get; set; }

    [DisplayName("Data Final Contrato")]
    [Required]
    [DataType(DataType.Date)]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
    public DateTime DataFinalContato { get; set; }  

View:

 <div class="form-group">

            <div class="col-md-3 col-sm-12">
                @Html.LabelFor(model => model.DataInicialContrato , htmlAttributes: new { @class = "control-label", @for = "datainicialcontrato" })
                @Html.EditorFor(model => model.DataInicialContrato, new { htmlAttributes = new { @class = "form-control ", @id = "datainicialcontrato"  } })
                <span class="help-block">@Html.ValidationMessageFor(model => model.DataInicialContrato, "", new { @class = "text-danger" })</span>
            </div>

            <div class="col-md-3 col-sm-12">
                @Html.LabelFor(model => model.DataFinalContato , htmlAttributes: new { @class = "control-label", @for = "datafinalcontrato" })
                @Html.EditorFor(model => model.DataFinalContato, new { htmlAttributes = new { @class = "form-control", @id = "datafinalcontrato" } })
                <span class="help-block">@Html.ValidationMessageFor(model => model.DataFinalContato, "", new { @class = "text-danger" })</span>
            </div>

 </div>

The datapicker is not appearing. I need a datapicker with DD / MM / YYYY format to appear in Portuguese.

    
asked by anonymous 08.12.2016 / 10:56

1 answer

2

For this you can use DatePicker Bootstrap as follows:

<div class="col-md-3 col-sm-12">
     @Html.LabelFor(model => model.DataInicialContrato , htmlAttributes: new { @class = "control-label", @for = "datainicialcontrato" })
     @Html.EditorFor(model => model.DataInicialContrato, new { htmlAttributes = new { @class = "form-control datepicker", @id = "datainicialcontrato"  } })
     <span class="help-block">@Html.ValidationMessageFor(model => model.DataInicialContrato, "", new { @class = "text-danger" })</span>
</div>

And no javascript :

<script type="text/javascript">
    $(function () { 
       $('.datepicker').datepicker();
    });
</script>
    
08.12.2016 / 11:53