Why the Json () function is unknown

I have the following code (in MVC3):

public JsonResult GetTown(string term) { db = new SHAMUTEntities1(); var data = db.towns.Where(t => t.name.Contains(term)) .Take(10) .Select(t => new {label=t.name }).ToArray(); return Json(data, JsonRequestBehavior.AllowGet); } } 

I get the following error:

System.Web.Helper.Json is a type, but used as a variable

Can anyone help with this. thanks

0
source share
1 answer

Json is a method of the System.Web.Mvc.Controller class of ASP.NET MVC 3. Since it does not compile, you probably use it in a class that is not obtained from Controller .

To fix this, simply return the data instance from your method and convert it to JSON in the controller method.

+7
source

All Articles