Multiple View Folders Based on URL parameter

71 views Asked by At

I have developed an MVC5 application for one of our client. It works fine. Now we have more clients where all the functionalities are same, but the view is different for each client(Not only the layout, but the html structure itself is different in each view).

What I was doing to distinguish the clients is to provide different urls, adding a client identifier (because we need to identify the client even before login), and filtereing it in the RouteConfig as given below:

routes.MapRoute("ClientRoute", "{client}/{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = 
UrlParameter.Optional },
            new RouteValueDictionary 
            { 
                { "client", "icici|federal|pnb|sbi" }  
            });

where the icici,federal,pnb and sbi are the valid clients.

and I could use this below code to distinguish the clients for any client specific logic.

var clientName = HttpContext.Current.Request.RequestContext.RouteData.Values["client"].ToString();

What I want is to have separate View folders for each client

  • Views (Default, should be taken from here if not found in other locations)
  • ICICI_Views
  • SBI_Views
  • FEDERAL_Views
  • PNB_Views
  • ....

these folders will have the layout and cshtml files. Any action having return View() or return View("viewname") should pick the corresponding views from the respected client folders.

Please help me if anyone know any solution to implement this (like configuring RouteConfig or DisplayModeProvider class, etc). I dont want to have a if-else check in each return view statement and specify the full path.

Thanks in advance :)

1

There are 1 answers

1
Aquib Iqbal On

You can specify the path of the view while returning from action method, For example if the client is ICICI then return View("~/ICICI_Views/Home/Index.cshtml"); and if no client found you can use return View();

return View("~/ICICI_Views/Home/Index.cshtml");