ASP.NET MVC JsonResult Date Format

前端 未结 25 3259
渐次进展
渐次进展 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:47

    Not for nothing, but there is another way. First, construct your LINQ query. Then, construct a query of the Enumerated result and apply whatever type of formatting works for you.

    var query = from t in db.Table select new { t.DateField };
    var result = from c in query.AsEnumerable() select new { c.DateField.toString("dd MMM yyy") };
    

    I have to say, the extra step is annoying, but it works nicely.

提交回复
热议问题