ASP.NET MVC JsonResult Date Format

前端 未结 25 3286
渐次进展
渐次进展 2020-11-21 11:22

I have a controller action that effectively simply returns a JsonResult of my model. So, in my method I have something like the following:

return new JsonRes         


        
25条回答
  •  情话喂你
    2020-11-21 11:53

    0

    In your cshtml,

                    
     {{value.FileReceivedOn | mydate | date : 'dd-MM-yyyy'}} 
    
    

    In Your JS File, maybe app.js,

    Outside of app.controller, add the below filter.

    Here the "mydate" is the function which you are calling for parsing the date. Here the "app" is the variable which contains the angular.module

    app.filter("mydate", function () {
        var re = /\/Date\(([0-9]*)\)\//;
        return function (x) {
            var m = x.match(re);
            if (m) return new Date(parseInt(m[1]));
            else return null;
        };
    });
    

提交回复
热议问题