https://github.com/bugthesystem/aspnet.mvc.theming
Enables implementing themes for ASP.NET MVC.
https://github.com/bugthesystem/aspnet.mvc.theming
asp-net-mvc c-sharp theme
Last synced: about 1 year ago
JSON representation
Enables implementing themes for ASP.NET MVC.
- Host: GitHub
- URL: https://github.com/bugthesystem/aspnet.mvc.theming
- Owner: bugthesystem
- License: gpl-2.0
- Created: 2013-11-19T16:28:52.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2017-05-27T21:45:24.000Z (about 9 years ago)
- Last Synced: 2025-03-11T02:08:40.199Z (over 1 year ago)
- Topics: asp-net-mvc, c-sharp, theme
- Language: C#
- Size: 786 KB
- Stars: 21
- Watchers: 11
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
AspNet.Mvc.Theming
======================
Enables implementing themes for ASP.NET MVC.
[](https://ci.appveyor.com/project/ziyasal/aspnet-mvc-theming)
* [Nuget Package - AspNet.Mvc.Theming](https://www.nuget.org/packages/AspNet.Mvc.Theming/)
To install AspNet.Mvc.Theming,
```bash
Install-Package AspNet.Mvc.Theming
```
>_**Area theme customization not implemented yet!**_
How to use;
-----------------------------
Create [**Themes**](https://github.com/ziyasal/AspNet.Mvc.Theming/tree/master/src/AspNet.Mvc.Theming.Sample/Themes) (or what you want) folder and put your themes to folder and initialize [**ThemeManager**](https://github.com/ziyasal/AspNet.Mvc.Theming/blob/master/src/AspNet.Mvc.Theming/ThemeManager.cs) to use this folder to apply theme and set default theme;
```csharp
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**](https://github.com/ziyasal/AspNet.Mvc.Theming/blob/master/src/AspNet.Mvc.Theming/Attributes/ThemeAttribute.cs) attribute to your controller to use theme you want.
```csharp
[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](https://github.com/ziyasal/AspNet.Mvc.Theming/blob/master/src/AspNet.Mvc.Theming.ThemeSelectorSample/Global.asax.cs#L7)
Sample: SessionThemeResolver
```csharp
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
```csharp
ThemeManager.Instance.Configure(config =>
{
config.ThemeDirectory = "~/Themes";
config.DefaultTheme = "Default";
config.ThemeResolver = new SessionThemeResolver();
});
```
Save theme to sesion
```csharp
Session["Theme"] = "YourTheme";
```