AspNet.Mvc.Theming
AspNet.Mvc.Theming copied to clipboard
Enables implementing themes for ASP.NET MVC.
AspNet.Mvc.Theming
Enables implementing themes for ASP.NET MVC.
To install AspNet.Mvc.Theming,
Install-Package AspNet.Mvc.Theming
Area theme customization not implemented yet!
How to use;
Create Themes (or what you want) folder and put your themes to folder and initialize ThemeManager to use this folder to apply theme and set default theme;
public class MvcApplication : System.Web.HttpApplication {
protected void Application_Start() {
//Omitted for brevity..
ThemeManager.Instance.Configure(config => {
config.ThemeDirectory = "~/Themes";
config.DefaultTheme = "Other";
});
}
}
Put Theme attribute to your controller to use theme you want.
[Theme("Default")]
public class WorkController : Controller
{
[HttpGet]
public ActionResult Index()
{
return View(new WorkModel
{
Content = "Hello World!"
});
}
}
Custom theme resolver
To implement your custom theme resolver see
Sample: SessionThemeResolver
public class SessionThemeResolver : IThemeResolver
{
public string Resolve(ControllerContext controllerContext, string theme)
{
string result;
if (controllerContext.HttpContext.Session != null && controllerContext.HttpContext.Session["Theme"] != null)
{
result = controllerContext.HttpContext.Session["Theme"].ToString();
}
else
{
result = (!string.IsNullOrEmpty(theme) ? theme : "Default");
}
return result;
}
}
init
ThemeManager.Instance.Configure(config =>
{
config.ThemeDirectory = "~/Themes";
config.DefaultTheme = "Default";
config.ThemeResolver = new SessionThemeResolver();
});
Save theme to sesion
Session["Theme"] = "YourTheme";