In my attendance portal, I've set the date range "Start" to "End". In these two fields I've used date picker so the admin can search the attendances from Whatever date he selected to whatever date he wanted. But I want my start date value to be one month before the current date. I've searched it a lot but can't find better one.
Here's my View code
- class="row">class="form-group">class="col-md-3">
- @Html.DropDownList("Employee",
- (IEnumerable
)TempData["Employees"], - "All Employee",
- new { @class = "form-control", onchange = "this.form.submit();" })
class="col-md-3">- "start" autocomplete="off" name="start" class="form-control datepicker" placeholder="Start" value="@startDate" />
class="col-md-3">- "end" class="form-control datepicker" autocomplete="off" name="end" placeholder="End" value="@endDate" />
class="col-md-3">- "submit" value="Search" class="btn btn-success" />
And here's my controller code
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult All(int? Employee, int? page, string start, string end)
- {
- List
attendanceList; - if (Employee != null)
- {
- if (start != "" && end != "")
- {
- DateTime dtstart = Convert.ToDateTime(start);
- DateTime dtend = Convert.ToDateTime(end);
- attendanceList = db.Attendance.ToList().Where(x => x.Emp_Id == Employee && x.Date >= dtstart && dtend >= x.Date).ToList();
- }
- else
- {
- attendanceList = db.Attendance.ToList().Where(x => x.Emp_Id == Employee).ToList();
- }
- return View(attendanceList);
- }
Mageshwaran RPosted Nov 16, 2020, 11:02 AM
Sachin SinghPosted Nov 16, 2020, 8:39 AM
Amit GuptaPosted Nov 16, 2020, 6:14 AM