In this article I will explain with an example, how to pass (send) data from Controller to View using Session in ASP.Net MVC Razor.
This article will illustrate how to save data in Session variable inside Controller and then access it using Razor syntax inside View in ASP.Net MVC Razor.
 
 
Passing (Sending) data from Controller to View using Session in ASP.Net MVC
In the below example, a string value is set in the Session object in Controller and it is then displayed in View using Razor syntax.
Controller
public class FirstController : Controller
{
    // GET: First
    public ActionResult Index()
    {
        Session["Message"] = "Hello MVC!";
        return View();
    }
}
 
View
<html>
<head>
    <meta name="viewport" content="width=device-width"/>
    <title>Index</title>
</head>
<body>
    <div>
        @Session["Message"]
    </div>
</body>
</html>
 
 
Screenshot
Pass (Send) data from Controller to View using Session in ASP.Net MVC
 
 
Downloads