asp.net mvc - MVC controller returns JSON. But to where? -
i'm new mvc. mvc controller returns viewresult. understand view has same action name. let's "dosomething" action goes "dosomething" view. if controller returns json, returned to? going page action method activated from? let's "index" vew "dosomething" action. if "dosomething" controller returns json, json go "index" view? working out returning json , jquery call ajax, confused. thanks.
if action method
returns json, view
doesn't involved. in cases, action method of controller returns response stream. notice return statement below. it's calling view first. think of method call. , whatever view
is, returned.
public actionresult dosomething() { return view(); }
in json's case notice view
stays out of it:
public jsonresult dosomething() { var jsondata = { "name" : "mike", "address" : "home", "gender" : "male" }; return json(jsondata, jsonrequestbehavior.allowget); }
jsondata caught javascript.
Comments
Post a Comment