This question is a result out of the discussion HERE and was moved from HERE.
Is it really good practice to supply EVERY value you display in any view via a model?
Especially variables like the current username. Even Microsoft odes the following in their default template for the _LoginPartial
in ASP.NET MVC 3+:
"Hello " + User.Identity.GetUserName() + "!"
I think this is OK to not supply this via a model as it is much better in light of maintainability. Or should you obay the "MVC rules" and add a model/sub-model to every page/model to supply such stuff and pass it around in your views and partials?
How do you solve such "problems" or what do you think is the best way of doing such stuff?
Inheritance would be an option:
public class BaseUserModel
{
public string UserName { get; set; }
}
Require every model to inherit from a base model like above containing such values.
But could that cause problems if you need/want to inherit another class for some model?