如何检索JsonResult数据 [英] How to retrieve JsonResult data
问题描述
我的版式控制器中有以下操作
I have the following Action in my layouts Controller
public JsonResult getlayouts(int lid)
{
List<layouts> L = new List<layouts>();
L = db.LAYOUTS.Where(d => d.seating_plane_id == lid).ToList()
return new JsonResult { Data = L, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
我正在从另一个控制器调用此动作,如下所示:
I am calling this Action from another controller like so:
layoutsController L = new layoutsController();
JsonResult result = L.getlayouts(lid);
我的问题是:如何从结果对象中获取数据?
My question is: how can I get the data from result object?
推荐答案
好,看看如何构建对象:
Well, have a look how you're building the object:
new JsonResult { Data = L, JsonRequestBehavior = JsonRequestBehavior.AllowGet }
您正在将L
变量设置为名为Data
的属性.因此,只需阅读该属性即可:
You're setting the L
variable to a property called Data
. So just read that property:
List<layouts> L = (List<layouts>)result.Data;
这是MVC控制器动作,对此没有什么特别的.
There's nothing special about the fact that it's an MVC controller action.
您只是在调用一个方法,该方法返回在该方法中构造的对象,并从该对象读取属性.就像其他C#代码一样.
You're simply calling a method which returns an object that was constructed in the method, and reading properties from that object. Just like any other C# code.
这篇关于如何检索JsonResult数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!