How to pass values from One controller to another Controller in ASP.Net MVC3

后端 未结 4 692
青春惊慌失措
青春惊慌失措 2021-01-14 08:19

Hello In my project I have to pass a welcome message with username to the Index Page Its a MVC3 ASP.Net Razor project

There are two controllers are there; O

4条回答
  •  礼貌的吻别
    2021-01-14 08:59

    You can try with Session, like

    Session["username"] = username;
    

    and for recover in the other controller use

    var username = (string)Session["username"]
    

    or in your redirect try with

    return RedirectToAction("Index", "Nome", new{ username: username})
    

    but the action of your controller must have as argument the (string username) like

    public ActionResult Index(string username)
    {
        return View();
    }
    

提交回复
热议问题