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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -