Show date from the client's driver in the View

0

I have a series of data that I bring from the server controller in an MVC.

As you can see in the image, the value of the date arrives well. When I save it in the Json to send it it is also saved well.

return new JsonResult()
            {
                Data = data,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet

            };

But when I see it on the screen, I find this:

In the HTML code, I simply do the binding, but the data has already arrived badly at this point.

<table  class='table'>
            <thead>
                <tr>
                    <th>Nombre de usuario</th>
                    <th>Rol</th>
                    <th>Estado</th>
                    <th>Fecha</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="usuario in data">
                    <td>{{usuario.Nombre}}</td>
                    <td>{{usuario.RolNombre}}</td>
                    <td>{{usuario.EstadoNombre}}</td>
                    <td>{{usuario.FechaAlta}}</td>
                </tr>
            </tbody>
        </table>

Let's see if anyone is able to lend me a hand ... other than the neck:)

I'm commenting on you.

{{usuario.FechaAlta | date:'dd-MM-yyyy'}}

It does not work for me, I've tried it, but as the 'badly formed' data arrives it does not work anymore

{ FechaAlta: $filter('date')(parseInt("/Date(1238540400000)/".substr(6)), 'dd/MM/yyyy') }

That option more or less I had thought about it but since I have a list of users I would have to create a buble to apply the change to all the records and it is not the option that I like the most.

And the last option is the same as this one :(

First of all I return to thank you because there are many options that you give me :) The only thing that the idea that I have is that I could deal with the data that already comes from the HTML if it were possible, the same can not be done, ...

    
asked by Bibi 21.11.2018 в 12:54
source

2 answers

1

One option would be to include the filter date of AngularJS after your HighDate field as follows:

{{usuario.FechaAlta | date:'dd-MM-yyyy'}}

or apply the same filter but on your controller

{ FechaAlta: $filter('date')(parseInt("/Date(1238540400000)/".substr(6)), 'dd/MM/yyyy') }

For this, you must remember to inject $filter in the "header" of your controller

app.controller('$scope', '$filter', function($scope, $filter){...})

If it does not work for you, you should extract the int that generates the date and pause it using a function as follows:

var date = new Date(tuFecha.match(/\d+/)[0] * 1).toLocaleDateString();

Another solution would be to edit the date on the same ng-repeat in the following way:

{{tuFecha.slice(6, -2) | date:'dd-MM-yyyy'}}

I mention that this last option was extracted from here , which also gives an excellent alternative to create a directive for handling dates from MVC

You tell us how are you doing =)

    
answered by 21.11.2018 в 14:31
0

In case someone happens to me, at the moment when I bring the data from the database, instead of saving it in a Datetime I have saved it as a string with the format 'dd / MM / yyyy 'and with that if it works for me.

objeto.FechaAlta = DateTime.Parse(row["FechaAlta"].ToString());
objeto.FechaAltaTexto = objeto.FechaAlta.ToString("dd/MM/yyyy");
    
answered by 21.11.2018 в 17:07