get a method to return json in C# and asp.net MVC 2 or 3 -
i use json return allot of results when building website, find myself writing a lot of code this:
return json(( s in searchresults select new { orderid = s.orderid, orderrealid = s.orderrealid, orderstatus = s.orderstatus, orderdate = s.orderdate, ordervenue = s.venuename + " - " + s.venuelocation + " (" + s.venuenumber + ")", orderstatustext = s.statusordervalue } ), jsonrequestbehavior.denyget);
what this:
public string resultstojson<t>(hashtable fields){ s in t select new { // loop through hash table } }
and call function whatever ienumerable results have question on right lines here, best possible way makes no sense writing in mvc , oop keep rewriting code ? in ? time.
many thanks
what types hashtable (dictionary<t,t>
since 2.0) hold? if it's plain dictionary<string,string>
write json trivially.
if has set of types have more types inside, way down leaf nodes worth looking @ json.net library instead, has far more advanced json capabilities standard .net json serializer.
Comments
Post a Comment