Search code examples
c#asp.net-mvcactionmethod

Call an action from another action without return statement


This is part of my Controller class:

if (ds.Tables.Count > 1)
{
    if (ds.Tables[0].Rows.Count > 0)
    {  
        dt = ds.Tables[0];
        dr = dt.Rows[0];

        TempData["AgentId"] = dr[0].ToString();
        TempData["AgentCode"] = dr[1].ToString();
        TempData["CenterName"] = dr[2].ToString();
        TempData["LevelName"] = dr[3].ToString();

        Session["AgentId"] = dr[0].ToString();
        Session["LogInSession"] = SessionId;

        return RedirectToAction("DashBoard", this.View(new AgentDetails { AgentId = Session["AgentId"].ToString() }));
        //return this.View("DashBoard", new AgentDetails { AgentId = Session["AgentId"].ToString()});
    }

I want to pass this argument and and call this action method separately. Is this possible?


Solution

  • An action is just a function. You can call it like any other function.

    var result = Dashboard();
    if(result.xxxx) // do whatever
    return View(new AgentDetails { AgentId = Session["AgentId"].ToString() });
    

    If that is what you want to do, then why don't you just refactor Dashboard code out into a method you can reuse?