asp.net mvc 4 - How to output a json object of Request.CreateResponse method -
how output json object of request.createresponse method?
the below code output json string
"{rowcount:15}"
,the string not json ojbect,it should use eval() method of javscript convert json object ,i want server side return json object directly, should return
{rowcount:15}
that's json object.
code
public class pageddataattribute : actionfilterattribute { public override void onactionexecuted(httpactionexecutedcontext actionexecutedcontext) { string jsonrowcount = "{rowcount:10}"; actionexecutedcontext.response = actionexecutedcontext.request.createresponse(system.net.httpstatuscode.ok, jsonrowcount,system.net.http.formatting.jsonmediatypeformatter.defaultmediatype); } }
instead of using string, use anonymous object:
public override void onactionexecuted(httpactionexecutedcontext actionexecutedcontext) { var rowcount = new { rowcount = 10 }; actionexecutedcontext.response = actionexecutedcontext.request.createresponse( httpstatuscode.ok, rowcount, jsonmediatypeformatter.defaultmediatype ); }
Comments
Post a Comment