ExtJS:如何使用 asp.net mvc 返回带有数据的 json 成功 [英] ExtJS: how to return json success w/ data using asp.net mvc
问题描述
我正在尝试将 ExtJS 与 Asp.Net MVC 一起使用,到目前为止一切顺利.(在 ExtJS 上做得很好)为了让事情更简单,我需要一些帮助,将数据从 .net 返回到 ExtJS.
I am trying to use ExtJS with Asp.Net MVC, and it is going fine so far. (Nice work on ExtJS) To make things easier, I need some help returning data from .net to ExtJS.
ExtJS 期望在 JSON 响应中看到成功标志以及附加数据.
ExtJS expects to see a success flag in the JSON Respone along with additional data.
示例预期响应格式类似于
a sample expectedresponse format is something like
{success: true, data: {id: 3, text: "hello world}}
{success: true, data: {id: 3, text: "hello world}}
那么,对于模型对象使用 linq2sql 或 ado.net 数据集,你们知道如何轻松以这种格式返回数据.
so, using either linq2sql or ado.net dataset for model objects, do you guys have any idea how to easily return data in this format.
类似的东西
public JsonResult Index()
{
result.success= true;
result.obj = repository.FindAllUsers();
return Json(result)
}
顺便说一下,这行得通吗?如果我有一个带有 bool success 和 Object 数据属性的 ExtJSResult 类?
would that work by the way? if I had a ExtJSResult class with bool success and Object data properties?
提前致谢
推荐答案
试试这个...
public JsonResult Index()
{
var json = new
{
success = true,
data = from user in repository.FindAllUsers().AsQueryable()
select new
{
id = user.Id,
name = user.Name,
...
}
};
return Json(json);
}
这篇关于ExtJS:如何使用 asp.net mvc 返回带有数据的 json 成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!