asp.net mvc - Setting the layout of ServiceStack Razor views on per-customer basis -


i working on servicestack-based web application used multiple clients. there default layout/design used in absence of client-specific one. hoping take advantage of support cascading layout templates available in servicestack razor having no luck making work.

here how have structured views in project:

\     _viewstart.cshtml     defaultlayout.cshtml     somesharedcontentpage.cshtml     \views         somesharedviewpage.cshtml         \clienta             layouta.cshtml             stylesa.css         \clientb             layoutb.cshtml             stylesb.css 

the logic in _viewstart.cshtml checks identity of logged-in user , sets appropriate layout kind of (in simplified form):

if (user.client.id == client_a_id)     layout = "~/views/clienta/layouta.cshtml"; else     layout = "~/views/clientb/layoutb.cshtml"; 

in turn, client-specific layouta , layoutb both use shared basic design/layout defined in defaultlayout.cshtml including following @ top:

@{     layout = "~/defaultlayout.cshtml"; } 

i hoping achieve cascading nested layout effect whereby both somesharedviewpage.cshtml , somesharedcontentpage.cshtml displayed final layout comprising both default , custom elements.

unfortunately doesn't work when hard-code 1 of layouts in view, nor when explicitly specify path of layout page (e.g. layout="~/views/clienta/layouta.cshtml" instead of layout="layouta").

what doing wrong?


update

i got top-level shared layout work renaming defaultlayout.cshtml _layout.cshtml client-specific layouts layouta , layoutb still not not being applied, ss razor falls _layout.cshtml convention.

i know support cascading nested layouts added servicestack, must doing wrong.

based on testing i've done, don't think servicestack razor supports _viewstart.cshtml. however, should able dynamically change layout via code using other methods. example, set this:

default.cshtml

<h2>default</h2> 

views\_layout.cshtml (the default servicestack razor)

@{     if (user.client.id == client_a_id)         layout = "_layout2";     else         layout = "_layout3"; } 

views\_layout2.cshtml

<h1>layout2</h1> @renderbody() 

views\_layout3.cshtml

<h1>layout3</h1> @renderbody() 

you should able use \views\clienta\alayout.cshtml have make sure layout files use unique name alayout.cshtml , blayout.cshtml.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -