Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. passing data from one action to another MVC asp.net

passing data from one action to another MVC asp.net

Scheduled Pinned Locked Moved Database
asp-netcsharphtmlcssarchitecture
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hunain Hafeez
    wrote on last edited by
    #1

    i am receiving Emplid in this action,

    public ActionResult showDDL(int? EmplID = null)
    {
    ViewBag.EmplID = EmplID;
    if (EmplID == null)
    {
    IEnumerable EmployeeAtd_2 = DataContext.GetAtdRecord_Sp(0).ToList();
    return View(EmployeeAtd_2);
    }
    else if (EmplID != null)
    {
    IEnumerable 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)
    {

    @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")
    ))

    using (Html.BeginForm("ToExcel", "Home", FormMethod.Get))
    {
    <button type="submit" class="button_form button_download" >Download in Excel</button>
    }

    }
    else
    {

    No Data Found

    }

    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();
            Syste
    
    Richard DeemingR 1 Reply Last reply
    0
    • H Hunain Hafeez

      i am receiving Emplid in this action,

      public ActionResult showDDL(int? EmplID = null)
      {
      ViewBag.EmplID = EmplID;
      if (EmplID == null)
      {
      IEnumerable EmployeeAtd_2 = DataContext.GetAtdRecord_Sp(0).ToList();
      return View(EmployeeAtd_2);
      }
      else if (EmplID != null)
      {
      IEnumerable 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)
      {

      @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")
      ))

      using (Html.BeginForm("ToExcel", "Home", FormMethod.Get))
      {
      <button type="submit" class="button_form button_download" >Download in Excel</button>
      }

      }
      else
      {

      No Data Found

      }

      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();
              Syste
      
      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      And what has this got to do with databases? You'll stand more chance of getting an answer if you post your question in the correct forum[^].


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups