asp.net mvc - Using a JSONResult in a C# function -
i have function returns jsonresult in below way.
var attachments = (from in ar.attachments select new { id = a.id, filename = a.filename }).toarray(); var result = new { comments = "some string", attachments = attachments }; return this.json(result);
i need use result in class need access "comments" , "attachments". here attachments string array , comments string. please let me know how can this.
you create viewmodel result , reuse class. viewmodel is, poco or dto. idea gives different way "look" @ data, nothing special really.
so end 3 parts.
the data method:
public commentsviewmodel getviewmodel() { var attachments = (from in ar.attachments select new { id = a.id, filename = a.filename }).toarray(); var result = new commentsviewmodel { comments = "some string", attachments = attachments }; return result; }
your controller method:
public jsonresult get() { return this.json(getviewmodel()); }
and other method call getviewmodel() directly. separate out bit you.
Comments
Post a Comment