Yogesh Vedpathak

Yogesh Vedpathak

  • 670
  • 1.4k
  • 197.8k

CS0103 The name json doesnot exist in current context .

Dec 15 2017 1:44 AM
using DemoGrids.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.Entity;
using System.Text;
namespace DemoGrids.BussinessService
{
public class BussinessServices
{
public JsonResult GetCustomers(String Word, int Page, int rows, string searchString)
{
using (DatabaseContext db = new DatabaseContext())
{
int PageIndex = Convert.ToInt32(Page) - 1;
int PageSize = rows;
string sort = string.Empty;
var Results = db.Customers.Select(
a => new
{
a.CustomerID,
a.ContactName,
a.ContactTitle,
a.City,
a.PostalCode,
a.Country,
a.Phone,
}).ToList();
int totalRecords = Results.Count();
var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows);
if (sort.ToUpper() == "DESC")
{
Results = Results.OrderByDescending(s => s.CustomerID).ToList();
Results = Results.Skip(PageIndex * PageSize).Take(PageSize).ToList();
}
else
{
Results = Results.OrderBy(s => s.CustomerID).ToList();
Results = Results.Skip(PageIndex * PageSize).Take(PageSize).ToList();
}
if (!string.IsNullOrEmpty(searchString))
{
Results = Results.Where(m => m.Country == searchString).ToList();
}
var jsonData = new
{
total = totalPages,
Page,
records = totalRecords,
rows = Results
};
return Json(jsonData, JsonRequestBehavior.AllowGet);  // error here
}
}
}
}

Answers (2)