ASP. net mvc skin replacement solution

Source: Internet
Author: User

This skin change refers to the dynamic switching of view folders, not CSS and image, you know ....

It is also very easy to use. The core is just a few words:

Public class Global: system. Web. httpapplication
{
Protected void application_start (Object sender, eventargs E)
{
Initrouting (routetable. routes );

// Use the Custom Skin view engine skinviewengine
// The View folder is/skins/skin name/controller name/
// Set the skin: httpcontext. setskinname (skin );
// Obtain the skin: String skinname = httpcontext. getskinname ();
Viewengines. Engines. Clear ();
Viewengines. Engines. Add (New skinviewengine (getskins ()));
}

Private Static void initrouting (routecollection routes)
{
Routes. maproute ("default", "{controller}/{action}", new {controller = "engine", Action = "Index "});
}

// (Traverse the skins directory) obtain all skin solutions provided by the website
Public static string [] getskins ()
{
List <string> skins = new list <string> ();
String skinfolder = httpcontext. Current. server. mappath ("~ /Skins /");
Foreach (string folder in directory. getdirectories (skinfolder ))
Skins. Add (New directoryinfo (folder). Name );
Return skins. toarray ();
}
}

 

Download the code:/files/surfsky/mvcskindemo.rar

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.