In this article I will explain with an example, how to assign Session value to Html.TextBox function in ASP.Net MVC.
The Controller consists of the following Action method.
Action method for handling GET operation
Inside this Action method, the Session objects are set and the View is returned.
public class HomeController : Controller
    // GET: Home
    public ActionResult Index()
        Session["Name"] = "Mudassar Khan";
        Session["Country"] = "India";
        return View();
Inside the View, there are two TextBoxes. The TextBox for the Name value is a simple HTML INPUT element while the TextBox for the Country value is created using Html.TextBox helper function.
For the HTML INPUT element, the Session object is set in the value attribute using the Razor Syntax while for the other TextBox, the Session object is passed to the value parameter of the Html.TextBox helper function.
    Layout = null;
<!DOCTYPE html>
    <meta name="viewport" content="width=device-width" />
    <table cellpadding="5">
            <td><input type="text" value="@Session["Name"]" /></td>
            <td>@Html.TextBox("txtMessage", Session["Country"])</td>
Assign Session value to Html.TextBox function in ASP.Net MVC