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.
I used @Wellington's answer with VS2010 (beta2) and MVC 2 (beta), and got the following error:
Method 'System.String ToString(System.String)' has no supported translation to SQL.
Which, I think, is a serialization problem (?)
Here's what I changed to make it work..
public JsonResult Index()
{
var json = new
{
success = true,
data = from user in repository.Users
select new JsonUser(user)
};
return Json(json);
}
JsonUser
is a simple, serializable object - I got the idea from a podcast by @Scott Hanselman
Here's an example of JsonUser
:
public class JsonUser
{
public long id { get; set; }
public string name { get; set; }
public string dateJoined { get; set; }
...
public JsonUser(User user)
{
id = user.ID;
name = user.Name;
dateJoined = user.DateJoined.ToString("yyyy-MM-dd");
...
}
}