i am receiving Emplid in this action,
public ActionResult showDDL(int? EmplID = null)
{
ViewBag.EmplID = EmplID;
if (EmplID == null)
{
IEnumerable<GetAtdRecord_SpResult> EmployeeAtd_2 = DataContext.GetAtdRecord_Sp(0).ToList();
return View(EmployeeAtd_2);
}
else if (EmplID != null)
{
IEnumerable<GetAtdRecord_SpResult> EmployeeAtd_2 = DataContext.GetAtdRecord_Sp(EmplID).ToList();
return View(EmployeeAtd_2);
}
return View();
}
View:
@{
var grid = new WebGrid(ViewData.Model, defaultSort: "EmplID", rowsPerPage: 20);
}
@if (Model.Count > 0)
{
<div id="AllEmpGrid_ByName">
@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>
using (Html.BeginForm("ToExcel", "Home", FormMethod.Get))
{
<button type="submit" class="button_form button_download" >Download in Excel</button>
}
}
else
{
<h2 class="error" >No Data Found</h2>
}
In same View you can see, button DOWNLOAD IN EXCEL, i want to pass this emplID to ToExcel method
public ActionResult ToExcel(int? empid )
{
var DataContext = new EmployeeRecordDataContext();
var grid = new GridView();
grid.DataSource = DataContext.GetAtdRecord_Sp(null).ToList();
grid.DataBind();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=AttendanceSheet.xls");
Response.ContentType = "application/ms-excel";
Response.Charset = "";
StringWriter sw = new StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
grid.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
return RedirectToAction("index");
}
i can't figure out that how to pass EmplID recieved in Action 'showDDL' to EmpID when i click Button "Download in Excel" ?