Yogesh Vedpathak

Yogesh Vedpathak

  • 669
  • 1.4k
  • 197.7k

The name(sort) Does not exist in current context

Dec 13 2017 2:15 AM
// Here Is My Code  
using DemoGrids.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace DemoGrids.Controllers
{
public class DemoController : Controller
{
// GET: Demo
public ActionResult Index()
{
return View();
}
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;
var Results = db.Customers.Select(
a => new
{
a.CustomerId,
a.ContactName,
a.ContactTitle,
a.City,
a.PostalCode,
a.Country,
a.Phone,
});
int totalRecords = Results.Count();
var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows);
// I a m Getting Error Here  Below  Line 
if (sort.ToUpper() == "DESC")
{
Results = Results.OrderByDescending(s => s.CustomerId);
Results = Results.Skip(PageIndex * PageSize).Take(PageSize);
}
else
{
Results = Results.OrderBy(s => s.CustomerId);
Results = Results.Skip(PageIndex * PageSize).Take(PageSize);
}
if (!string.IsNullOrEmpty(searchString))
{
Results = Results.Where(m => m.Country == searchString);
}
var jsonData = new
{
total = totalPages,
Page,
records = totalRecords,
rows = Results
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
}
}
}

Answers (2)