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.
样本expectedresponse格式是一样的东西。
a sample expectedresponse format is something like
{成功:真实的,数据为:{ID:3,文字:你好世界}}
{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)
}
将由方式工作?如果我与布尔的成功和对象数据属性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屋!