Reputation: 442
I am stuck by an annoying problem in my code. I am using DATE FROM----DATE TO boxes to select range of date to display employees between that date ranges in WEBGRID but problem is that in first display it appears exactly according to that date ranges but when i do pagination (clicking page 2, 3 , 4....) then it picks all employees record for every date because i have set IF condition like that if DatFrom and TO are empty then pick all results
so how to implement it correctly ?
public ActionResult ShowCalTextBox(String DateFrom, String DateTo)
{
if (DateFrom != "" && DateTo == "")
{
IEnumerable<GetEmpRec_DateResult> EmpRec_DateFrom = DataContext.GetEmpRec_Date(DateFrom, null).ToList();
ViewBag.Dates = "Records for"+" "+ DateFrom ;
return View(EmpRec_DateFrom);
}
else if (DateFrom == "" && DateTo != "")
{
IEnumerable<GetEmpRec_DateResult> EmpRec_DateTo = DataContext.GetEmpRec_Date(null, DateTo).ToList();
ViewBag.Dates = "Records for" + " " + DateTo;
return View(EmpRec_DateTo);
}
else if (DateFrom != "" && DateTo != "")
{
IEnumerable<GetEmpRec_DateResult> EmpRec_ByDate = DataContext.GetEmpRec_Date(DateFrom, DateTo).ToList();
ViewBag.Dates = "Records from" + " " + DateFrom +" "+"to"+" "+DateTo;
return View(EmpRec_ByDate);
}
else if (DateFrom == "" && DateTo == "")
{
IEnumerable<GetEmpRec_DateResult> EmpRec_Default = DataContext.GetEmpRec_Date(null, null).ToList();
ViewBag.Dates = "No date selection";
return View(EmpRec_Default);
}
return View();
}
public ActionResult About()
{
return View();
}
actually i think problem is here
public ActionResult ShowCalTextBox(String DateFrom, String DateTo)
{
if (DateFrom != "" && DateTo == "")
{
IEnumerable<GetEmpRec_DateResult> EmpRec_DateFrom = DataContext.GetEmpRec_Date(DateFrom, null).ToList();
ViewBag.Dates = "Records for"+" "+ DateFrom ;
return View(EmpRec_DateFrom);
}
VIEW:
@using EmployeeAttendance_app.Models
<div>
@using (Html.BeginForm("ShowCalTextBox", "Home", FormMethod.Post))
{
<label id="lblFrom">From</label>
<input type="text" id="TxtBoxFrom" name="DateFrom" />
<label id="lblTo">To</label>
<input type="text" id="TxtBoxTo" name="DateTo" />
<br />
<br />
<button type="submit" id="btnSubmitDate" name="btnSubmit">Submit</button>
}
</div>
<div>
<h4>@ViewBag.Dates</h4>
<br />
@{
var grid = new WebGrid(ViewData.Model, rowsPerPage: 20, canPage: false);
}
<div id="AllEmpGrid_ByDate">
@grid.GetHtml(columns: grid.Columns(
grid.Column("EmplID", "Employee ID"),
grid.Column("EmplName","Employee Name"),
grid.Column("ShiftID", "Shift ID"),
grid.Column("DateVisited", "Date of Visit"),
grid.Column("InTime", "In Time"),
grid.Column("TimeOut", "Time Out"),
grid.Column("OverTime", "Over Time"),
grid.Column("TotalWorkingTime", "Total Working Time")
))
</div>
</div>
Upvotes: 1
Views: 56
Reputation: 2387
The reason is that the page grid makes a get request instead of post. Possibly you can get hold of it by including the following javascript code:
<script type="text/javascript">
$(function () {
$('th a, tfoot a').click(function () {
$('form').attr('action', $(this).attr('href')).submit();
return false;
});
});
</script>
Upvotes: 1