Can anybody please tell me where I am going wrong with this. I have a list of errors and I want to be able to search by date. For example, if I selected the date, 20/08/2015, from a date picker, then I want the list to just show errors from that date. By default it will show all the errors in the database, but when a date is selected, I want to show only the errors from that date.
Controller
[HttpPost]
public ActionResult Index(string sortOrder, int? page, DateTime? datePicker)
{
ViewBag.CurrentSort = sortOrder;
ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date";
DateTime userSelectedDate = DateTime.Parse(Request["datePicker"]);
var applications = from s in db.ElmahErrors
where s.TimeUtc == userSelectedDate
select s;
switch (sortOrder)
{
default:
applications = applications.OrderByDescending(x => x.TimeUtc);
break;
}
int pageSize = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["DefaultPageSize"]);
int pageNumber = (page ?? 1);
return View(applications.ToPagedList(pageNumber, pageSize));
}
View
@using (Html.BeginForm())
{
<label for="datePicker">Find By Date:</label>
@Html.TextBox("datePicker", null, new { @type = "date" })
<input id="submitBtn" type="submit" value="Search" />
}
The userSelectedDate
variable is taking in the value from the date picker, but it doesn't match any of the errors. Can somebody please help?
Thanks in advance.