Wednesday, June 26, 2013

How to use contains ,Between and List generic in Linq with MVC?

public class CustomerController : Controller

{

List<Customer> Customers = new List<Customer>();

public CustomerController()

{

string []str = {"1","2","12"};



var dataContext = new CustDBDataContext();

Customers = (from m in dataContext.tbl1s where str.Contains(Convert.ToString(m.Id)) && m.Id>0 && m.Id<12

select new Customer { Id = (int)m.Id, Name = m.Name, Amount = (double)m.Amount }

).ToList();

}

public ViewResult DisplayCustomer(int id)

{

List<Customer> objCustomer1 = Customers.FindAll(delegate(Customer cst) { return cst.Id == id; });

Customer objCustomer = objCustomer1[0];

return View("DisplayCustomer", objCustomer);

}

public ViewResult Details()

{

return View(Customers);

}

}

No comments:

Post a Comment