asp.net mvc - Converting date format to -
hi guys/girls im super new asp.net mvc , im trying convert date readable format. looks this.
/date(1444892163827)/
my model
public class movie { internal string title; internal datetime releasedate; internal string genre; public int id { get; set; } [required] public string title { get; set; } public datetime releasedate { get; set; } [required] public string genre { get; set; } } public class moviedbcontext : dbcontext { public dbset<movie> movies { get; set; } }
my controller
public jsonresult getall() { using (moviedbcontext datacontext = new moviedbcontext()) { var movielist = datacontext.movies.tolist(); return json(movielist, jsonrequestbehavior.allowget); } } public jsonresult getmoviebyno(string movno) { using (moviedbcontext datacontext = new moviedbcontext()) { int no = convert.toint32(movno); var movielist = datacontext.movies.find(no); return json(movielist, jsonrequestbehavior.allowget); } }
any appreciated !
you need create customjsonresult in mvc use example json.net isodatetimeconverter or should change project mvc webapi if return json.
create class https://stackoverflow.com/a/9302054/4599089 (approach 2) , use in controller:
public jsonresult getall() { using (moviedbcontext datacontext = new moviedbcontext()) { var movielist = datacontext.movies.tolist(); return new customjsonresult(){data = movielist}; } } public jsonresult getmoviebyno(string movno) { using (moviedbcontext datacontext = new moviedbcontext()) { int no = convert.toint32(movno); var movielist = datacontext.movies.find(no); return new customjsonresult(){data = movielist}; } }
Comments
Post a Comment