Tom Carter Tom Carter - 2 months ago 5x
ASP.NET (C#) Question

How to save name for user in all views in ASP MVC?

I am creating a simple chat application, where user chooses his name in homepage and then, he can be sending messages in chat page. I dont know how to remember user's name without using model. Any help?


You could store it in Session. Assign it in a controller like Session["UserName"] = "John Doe"; Then, in the View you can access @Session["UserName"] directly, or pass it on via a ViewModel.