Answer the question
In order to leave comments, you need to log in
How to do search by date in ASP.Net MVC 5?
I can’t set up a search for a record by date in the application
. I have 3 fields:
Search by customers and material works as it should, I wrote as:
[HttpPost]
public ActionResult OrdersByCustomers(string name)
{
var allOrdersByCustomers = db.Orders
.Where(a => a.Customer.CustomerName.Contains(name))
.Include(p => p.Customer)
.Include(p => p.Material)
.ToList();
if (allOrdersByCustomers.Count >= 0)
{
return View(allOrdersByCustomers);
}
return View();
}
[HttpPost]
public ActionResult OrdersByMaterials(string name)
{
var allOrdersByMaterials = db.Orders
.Where(a => a.Material.Name.Contains(name))
.Include(p => p.Customer)
.Include(p => p.Material)
.ToList();
if (allOrdersByMaterials.Count >= 0)
{
return View(allOrdersByMaterials);
}
return View();
}
[HttpPost]
public ActionResult OrdersByDate(DateTime date)
{
var allOrdersByDate = db.Orders
.Where(a => a.Date.Contains(date)) //В этом моменте дает ошибку, говорит, что дата не может Contains
.Include(p => p.Customer)
.Include(p => p.Material)
.ToList();
if (allOrdersByDate.Count >= 0)
{
return View(allOrdersByDate);
}
return View();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question