从Controller返回JSON对象以进行查看 [英] Return JSON object from Controller to view

查看:117
本文介绍了从Controller返回JSON对象以进行查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试将一个对象(项目)从我的Controller发送到我的视图,如下所示。

Hi,

I am trying to send an object(item) from my Controller to my View as shown below.

var item = new
   {
      rows = (from p in storeDB.Products
              where p.ProductID == id
              select p).ToArray()
   };
   return Json(item, JsonRequestBehavior.AllowGet);



但每当我尝试这样做时该对象永远不会返回到视图,而是进入MyDatabase.Designer.cs文件内的无限循环。请帮助。


But whenever I try to do so the object is never returned to the view instead it goes into an infinite loop inside MyDatabase.Designer.cs file. Pls help.

推荐答案

尝试这样的事情:

不要选择p选择新的[]并确保所有项目是字符串,如果没有转换它们。

Try something like this:
don''t select p select a new[] and make sure that all items are string, if not convert them.
rows = (from p in storeDB.Products
where p.ProductID == id
select
new[] { Convert.ToString(p.Id), p.Name,
                           p.Description,p.Category, Convert.ToString(p.Value) };
).ToArray()
};


这篇关于从Controller返回JSON对象以进行查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆