TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Yogesh Vedpathak
674
1.4k
191.7k
An exception of type 'System.NullReferenceException' occurre
Dec 18 2017 12:51 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 variable GetCustomers(String Word, int Page, int rows, string searchString)
{
variable v = new variable();
List<CustomerViewModel> customermodel = new List<CustomerViewModel>();
using (DatabaseContext db = new DatabaseContext())
{
v.PageIndex = Convert.ToInt32(Page) - 1;
v.PageSize = rows;
customermodel = (from customer in db.Customers
select new CustomerViewModel
{
CustomerID = customer.CustomerID,
ContactName = customer.ContactName,
ContactTitle = customer.ContactTitle,
City = customer.City,
PostalCode = customer.PostalCode,
Country = customer.Country,
Phone = customer.Phone
}).ToList();
v.totalRecords = customermodel.Count();
v.totalPages = (int)Math.Ceiling((float)v.totalRecords / (float)rows);
if (v.sort.ToUpper() == v.DESC) // getting error here
// if (v.sort.ToUpper() == "DESC")
{
customermodel = customermodel.OrderByDescending(s => s.CustomerID).ToList();
customermodel = customermodel.Skip(v.PageIndex * v.PageSize).Take(v.PageSize).ToList();
}
else
{
customermodel = customermodel.OrderBy(s => s.CustomerID).ToList();
customermodel = customermodel.Skip(v.PageIndex * v.PageSize).Take(v.PageSize).ToList();
}
if (!string.IsNullOrEmpty(searchString))
{
customermodel = customermodel.Where(m => m.Country == searchString).ToList();
}
var jsonData = new
{
total = v.totalPages,
Page,
records = v.totalRecords,
rows = customermodel
};
return new variable {total=v.totalPages,PageIndex=v.PageIndex,records=v.records,customerModel= customermodel };
}
}
}
}
Reply
Answers (
5
)
Rss News Feed using Asp.net using C#
Create API in asp C# .net