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 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}}
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.
Something like
public JsonResult Index()
{
result.success= true;
result.obj = repository.FindAllUsers();
return Json(result)
}
would that work by the way? if I had a ExtJSResult class with bool success and Object data properties?
thanks in advance
Try this one...
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With