Ok. I've finally solved this.
I'm, creating a base model that all of my other view-models are going to inherit from. It can also be called directly in case any view doesn't require its own view-model.
public class ViewModelBase
{
public UserSettings ProfileSettings;
// Create a new instance, so we don't need to every time its called.
public ViewModelBase()
{
ProfileSettings = new UserSettings();
}
}
public class UserSettings // UserSettings is only used here and consumed by ViewModelBase, its the name there that is used throughout the application
{
public string BrandName { get; set; }
public UserRegistrationInformation UserSession;
}
This is being generated in the basecontroller.
public abstract class BaseController : Controller
{
public ViewModelBase vmb = new ViewModelBase();
protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
{
string cultureName = null;
int userid = 0;
if (System.Web.Security.Membership.GetUser() != null)
{
//logged in
userid = (int)System.Web.Security.Membership.GetUser().ProviderUserKey;
WebUsersEntities db = new WebUsersEntities();
vmb.ProfileSettings.UserSession = db.UserRegistrationInformations.Where(r => r.uri_UserID == userid).FirstOrDefault();
vmb.ProfileSettings.BrandName = "test";
cultureName = "es-es";
}
else
{
// not logged in
cultureName = Request.UserLanguages[0]; // obtain it from HTTP header AcceptLanguages
}
// Validate culture name
cultureName = CultureHelper.GetImplementedCulture(cultureName); // This is safe
// Modify current thread's cultures
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureName);
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
return base.BeginExecuteCore(callback, state);
}
}
The other controllers all inherit from this controller. If any screen has a dedicated view-model it can retrieve the information from the model populated in the controller like this:
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
LoginModel v = new LoginModel();
v.ProfileSettings = vmb.ProfileSettings;
ViewBag.ReturnUrl = returnUrl;
return View(v);
}
I hope that helps someone in the future.