Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
CSS
How to apply the themes dynamically by selecting the theme from the dropdownlist in Asp.net MVC4? I want to apply the theme on selection.
Posted

1 solution

Not the exact solution but still it's worth to look:
ASP.NET MVC Dynamic Themes[^]
You can customize the code as per your need.

And apart from this, you can do it using jQuery. Create the different .css files for each theme and based on the selection, load the theme for the page.
See,
C#
$(".changeStyle").click(function (e) {
    e.preventDefault();
    var style = $(this).attr("data-style");
    $("#siteStyle").attr("href", style);
    localStorage.setItem("selected-skin", style);

});

// load selected color skin
if (localStorage.getItem("furnitureshop-skin"))
{
    $("#siteStyle").attr("href", localStorage.getItem("selected-skin"));
}

HTML:
XML
<div class="panel-body">
             <label>Select the color theme</label>
             <ul class="skin-colors">
                 <li>
                     <a href="#" class="changeStyle" style="background-color: rgba(125, 63, 10, 1)" data-style="/Content/Site.css"></a>
                 </li>
                 <li>
                     <a href="#" class="changeStyle" style="background-color:#000" data-style="/Content/Black-Skin.css"></a>
                     </li>
                 <li>
                     <a href="#" class="changeStyle" style="background-color: #8C489F" data-style="/Content/Purple-Skin.css"></a>
                 </li>
                 <li>
                     <a href="#" class="changeStyle" style="background-color: #DF3232" data-style="/Content/Red-Skin.css"></a>
                 </li>
             </ul>
         </div>


-KR
 
Share this answer
 
Comments
Susan Marampudi 15-Jul-15 23:25pm    
Thanks Rohit, your solution gave me some idea.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900