Dismember date to load javascript

Asked

Viewed 116 times

0

I have in BD a Datanascimento field, where it is gurdada in YYYY-mm-dd format. I have a javascript function that scans the table by last CPF. If there is registration for the CPF, then it assembles the fields in the form. It turns out that the Date of Birth, in the form, is mounted with three option objects (Combobox), like this: Dia Mes Ano.

How do I make in my controller a method that returns me the date of the BD dismembered, for me to click in my form?

Use LINQ like this:

var Result = (from a in db.TB_CLIENTES
                              where a.CdCliente == "1" && a.CPF == _cpf
                              select new
                              {
                                  a.Nome,
                                  a.Endereco,
                                  a.Numero,
                                  a.CEP,
                                  a.Complmento,
                                  a.Telefone,
                                  a.Celular

                              }).ToList();
  • What is the type of property DataNascimento on your domain model? It’s string, or is DateTime?

  • I solved it like this: Dia = a.DataNascimento.Value.Day, Mes = a.DataNascimento.Value.Month, Year = a.DataNascimento.Value.Year, completing my LINQ

1 answer

1

var Result = (from a in db.TB_CLIENTES
    where a.CdCliente == "1" && a.CPF == _cpf
    select new
    {
        Nome = a.Nome,
        Endereco = a.Endereco,
        Numero = a.Numero,
        CEP = a.CEP,
        Complemento = a.Complemento,
        Telefone = a.Telefone,
        Celular = a.Celular,
        DiaNascimento = a.DataNascimento.Value.Day,
        MesNascimento = Ano = a.DataNascimento.Value.Month,
        AnoNascimento = a.DataNascimento.Value.Year
    }).ToList();

Browser other questions tagged

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