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" ?

please close down this boring and useless site, as no one replies to any post.

My first suggestion is to modify your form submission a "post" transaction to follow normal practice as follows:

 using (Html.BeginForm("ToExcel", "Home"))

Next the submit will issue a post request from your form so you will need to annotate the ToExcel action to identify it as a post action:

[HttpPost]
public ActionResult ToExcel(int? empid )

Remaining problem is that what gets submitted in the post will be the contents of your form which at the moment is empty so nothing will get submitted. At this point I'm unclear what you are trying to do but to answer your question since the empid is in the ViewBag for the view you could simply add the following hidden field to your form and it will be returned with the form post:

 using (Html.BeginForm("ToExcel", "Home", FormMethod.Get))
 {
    <input type="hidden" name="empid" value="@ViewBag.EmplID">
   <button type="submit" class="button_form button_download" >Download in Excel</button>
 }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.