📜  如何从 mvc 控制器返回 json 数据以查看 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:34.350000             🧑  作者: Mango

代码示例1
When 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.

If you instead want to return a view, just do return View(...) like you normally would:

var dictionary = listLocation.ToDictionary(x => x.label, x => x.value);
return View(new { Values = listLocation });
Then in your view, simply encode your data as JSON and assign it to a JavaScript variable: