how to return json data from mvc controller to view

Solutions on MaxInterview for how to return json data from mvc controller to view by the best coders in the world

showing results for - "how to return json data from mvc controller to view"
Elías
26 Feb 2020
1When you do return Json(...) you are specifically telling MVC not to use a view, and to serve serialized JSON data. Your browser opens a download dialog because it doesn't know what to do with this data.
2
3If you instead want to return a view, just do return View(...) like you normally would:
4
5var dictionary = listLocation.ToDictionary(x => x.label, x => x.value);
6return View(new { Values = listLocation });
7Then in your view, simply encode your data as JSON and assign it to a JavaScript variable:
8
9<script>
10    var values = @Html.Raw(Json.Encode(Model.Values));
11</script>
queries leading to this page
display json data in mvc viewreturn result in json asp net mvcasp net mvc return json objecthow to print return jsonresult from mvc controller c 23how to return json from action method in mvchow to return json in mvc controllerjson result to send json in view mvcreturn json in mvcc 23 mvc 5 controller return jsonhow to return json data from mvc controllerreturn json data from controller how to return value from controller to view using jsonresult in mvcmvc return json objectreturn json in mvc asp netmvc jsonresult returnsend json result to view in mvcjson response from one controller to another controller in mvcreturn json from mvc action methodhow to return api json data from mvc controller to viewmvc get json result in getreturn json string from mvc controller javareturn json data in mvchow to return view with json in mvcreturn json in mvc c 23return asp net model to json in controllerreturn json data from controller to view mvcmvc controller returning json to viewjson result in mvcreturn json mvc seereturn json result from mvc controllerhow return json in mvc mvc model return jsonmvc return json from modelreturn mvc model data in jsonresult in c 23mvc get json datamvc return json response texthow to send and receive json data to and from the controller in mvcload view and json result in mvc 5creturn jsonresult in mvcmvc api how to return jsonasp mvc return jsonmvc controller receive json objectmvc return jsonwith viewmvc return jsonresulthow to retrieve json data in controller mvc asp nethow to return model with json in mvchow to get json response from controller in view mvc 5mvc api controller return jsonmvc jsonresult get datareturn json in mvc controller c 23get json from controller mvc net return json from controllerget json mvc controllermvc return json with and modeljson result how get mvcdisplay json data from controller to view in asp net mvcjson return in mvcmvc return view with json datahow to return json data from mvc controller to viewget data from json controllerreturn view with json data in mvcmvc controller return jsonreturn json from mvchow to get json result from controller mvcmvc return json result piafsdkasp mvc return json from api controllerreturn json result mvcreturn application json from asp net mvc controllerreturn json from mvc controller c 23return json in mvc controller helper classjsonresult in mvc returnhow to pass data from controller to view in mvc already return json controller get json datahow to send json data to controller in mvc mvc 5 send json to view from controllermvc return json and view get jsonreturn json object from controller action in asp net mvcreturn json in the mvc web api c 23 controller how to read json data in mvc controllerhow to display json data in mvc view how to pass jsonresult to view in mvc and read datareturn json asp net mvcmvc api return json resultmvc return json result c 23send json from view to controllerreturn json result and show mvc viewreturn json result in mvcmvc return jsonhow to get json from controllerhow to return json in asp net mvchow to return json data from mvc controller to view