I can not use the Date field. I am using Asp.Net C # MVC

0

function set_dados_form(dados) {
  $('#id_cadastro').val(dados.Id);
  $('#txt_Nome').val(dados.Nome),
    $('#txt_Telefone').val(dados.Telefone),
    $('#txt_Endereco').val(dados.Endereco),
    $('#txt_Data').val(dados.DataNascimento),
    $('#cbx_Ativo').prop('checked', dados.Ativo);
}
<div class="form-group">

  @Html.Label("txt_Data", "Data", new { @class = "col-md-3 control-label" })
  <div class="col-md-12">
    <input type="date" name="txt_Data" id="txt_Data" class="col-md-4 control-label" />

  </div>
</div>

I can not feed the Date field. With the date that comes from a query, an ex value is coming: "01/01/2017" (type a string), but when putting in the property val (referring to the jquery) nothing appears. Someone help me !!!

    
asked by anonymous 01.10.2017 / 19:20

1 answer

0

Are you passing the value in what format?

If it is in that format = > "01/01/2017" is incorrect. First you'll need to format for this="2017-01-01" and then you'll be able to assign.

Here's an example of how to use it.

Explanation, I put dbclick only to quickly test if employee. What really matters here is FormatData function. It should receive a date in the following format: 'YYYY / MM / DD'

then it will return a date in the format accepted by its date field, which is 'YYYY-MM-DD'

Remembering that where I put the fixed date, you should pass your variable.

 $('#txt_Data').dblclick(function () {     


   $('#txt_Data').val(formataData('2017/04/01'));
})
function formataData(data) {
    var array = data.split('/');
    var data = array[0] + '-' + array[1] + '-' + array[2];

    return data;

}
    
02.10.2017 / 00:43