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

Asked

Viewed 296 times

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’t feed Camp Date. With Date coming from a query, an ex:"01/01/2017" value is coming (type a string), but when placing in the val property (referring to jquery) nothing appears. Somebody help me!!!

1 answer

0

You are passing the value in which format?

If this format => "01/01/2017" is incorrect. First you need to format for this = "2017-01-01" and then you can assign.

Here’s an example of how to use.

Explanation, I put the dbclick only to test quickly if employee. What matters even here is function formatted. 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 must 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;

}
  • Thank you so much for your help, I’ll try here to see if it works.

  • Unfortunately it did not work, look what returned me -Date(765514800000)-

  • Are you sure that data.Databirth, is in the quoted format? Because the code I passed was tested.

Browser other questions tagged

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