c# - Abstraction layer between Controller and View -


i trying create layer between controller , view can pass different versions of view user based on "client id" company belong.

i have following code:

public class homecontroller : controller {     //     // get: /home/     public actionresult index()     {         // set client         var client = new client();         client.id = guid.newguid();         client.name = "foo";          // set user         var user = new user();         user.id = guid.newguid();         user.clientid = client.id;         user.name = "foo";          return viewrenderer.renderview("addcomplete", client);     } } 

my viewrenderer class looks this:

public static class viewrenderer {     public static viewresult renderview(string view, guid clientid)     {         string viewname = getviewforclient(view, clientid);         return controller.view(view);     }      public static string getviewforclient(string view, guid clientid)     {         // todo: logic return view specific company user belongs...     } } 

the problem is, line return controller.view(view); in renderview(string view, guid clientid) gives me error:

system.web.mvc.controller.view()' inaccessible due protection level

i interested know how can resolve error or if there better way trying do, display different versions of view specific respective company user belongs.

edit: option kicking around in head...

is there way override view() method such can prepend directory name, example, user belongs "acme co." call same controller action else view("myview") method calling view("acmeco/myview") however, don't write code in controller, it's derived user's client id property.

the view() method protected member. can access within derived type, such homecontroller class. plus you're trying access static method.

you can create base controller exposes specialized view logic. sake of illustration, i'm going call dynamicviewcontrollerbase

public class homecontroller : dynamicviewcontrollerbase {     //     // get: /home/     public actionresult index()     {         // set client         var client = new client();         client.id = guid.newguid();         client.name = "foo";          // set user         var user = new user();         user.id = guid.newguid();         user.clientid = client.id;         user.name = "foo";          return renderview("addcomplete", client);     } }  public class dynamicviewcontrollerbase : controller {     protected viewresult renderview(string view, guid clientid)     {         string viewname = getviewforclient(view, clientid);         return view(view);     }      // unless plan use methods , properties within      // instance of `controller`, can leave      // static method.     private static string getviewforclient(string view, guid clientid)     {         // todo: logic return view...     } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -