Skip to content
Loading
  
And here's my controller code
  1. [HttpPost]  
  2. [ValidateAntiForgeryToken]  
  3. public ActionResult All(int? Employee, int? page, string start, string end)  
  4. {  
  5. List attendanceList;  
  6. if (Employee != null)  
  7. {  
  8. if (start != "" && end != "")  
  9. {  
  10. DateTime dtstart = Convert.ToDateTime(start);  
  11. DateTime dtend = Convert.ToDateTime(end);  
  12. attendanceList = db.Attendance.ToList().Where(x => x.Emp_Id == Employee && x.Date >= dtstart && dtend >= x.Date).ToList();  
  13. }  
  14. else  
  15. {  
  16. attendanceList = db.Attendance.ToList().Where(x => x.Emp_Id == Employee).ToList();  
  17. }  
  18. return View(attendanceList);  
  19. }  
  In the above example the start date will always be one month before the current date and end date will always be one month after the current date , however admin is free to select any date he wants.
+1
  • Mageshwaran R
    0
    Hi Hamza,
    please try this code,
    1. var lastmonth = DateTime.Today.AddMonths(-1);   
    0