Trying to create a list to return some JSON data to a view. Following a few tutorials on the web that were created during the beta but it seems in the RC the code does work.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace MvcApplication6.Controllers { [HandleError] public class HomeController : Controller { public JsonResult list() { List<ListItem> list = new List<ListItem> { new ListItem() {Name="value", Something = "more Values"} }; return Json(List); } } }
The problem is ListItem is not found in the System.Web.Mvc namespace. I can’t seem to get this to work. If ListItem has been removed how do you accomplish this in Release Candidate MVC?
Here are the tutorials I am trying to use:
http://geekswithblogs.net/michelotti/archive/2008/06/28/mvc-json—jsonresult-and-jquery.aspx http://nayyeri.net/blog/using-jsonresult-in-asp-net-mvc-ajax/
ListItem is in the System.Web.UI.WebControls…you probably don’t want to use this. You could use SelectListItem which is in the System.Web.Mvc namespace, but you’ll have to change the property names (you’d have to do this for ListItem as well).
I’d be tempted to do this with List<object> and anonymous types so that I could define the property names to my liking.