Reputation: 814
I just readed answers from this question Use Session variable in html, but this is not working for me. I tried =
instead of :
but same thing. I tried this also:
Hello <%Response.Write(Session("username"))%>
but nothing happens. I am using MVC pattern in ASP.NET application. I want to have format:
"Hello Username"
shown on the screen but instead of that I have
"Hello <%:Session["username"]%>".
This is my code in .cs
file:
Session["username"] = user.Username;
return RedirectToAction("Index", "Home");
This is my code in .cshtml
file:
@if (Session["username"] != null)
{
<li>
Hello <%:Session["username"]%>
</li>
}
Any other idea?
Upvotes: 0
Views: 2759
Reputation: 11963
The <%
syntax is for old asp.
For razor, you can simply do @Session["username"]
.
Upvotes: 1