asp.net mvc - When should a page use a layout in MVC? -


when should page use layout or render layout? i'm little confused when should create page page using layout.

different between

@{     layout = null; } 

and

@{     viewbag.title = "edit";     layout = "~/views/shared/_layout.cshtml"; } 

ade,

i answered similar question while back:

*from scottgu's blog (ref: http://weblogs.asp.net/scottgu/archive/2010/10/22/asp-net-mvc-3-layouts.aspx):

starting asp.net mvc 3 beta release, can add file called _viewstart.cshtml (or _viewstart.vbhtml vb) underneath \views folder of project:

the _viewstart file can used define common view code want execute @ start of each view’s rendering. example, write code within our _viewstart.cshtml file programmatically set layout property each view sitelayout.cshtml file default:

because code executes @ start of each view, no longer need explicitly set layout in of our individual view files (except if wanted override default value above).

important: because _viewstart.cshtml allows write code, can optionally make our layout selection logic richer basic property set. example: vary layout template use depending on type of device accessing site – , have phone or tablet optimized layout devices, , desktop optimized layout pcs/laptops. or if building cms system or common shared app used across multiple customers select different layouts use depending on customer (or role) when accessing site.

this enables lot of ui flexibility. allows more write view logic once, , avoid repeating in multiple places.*

see where , how _viewstart.cshtml layout file linked? details


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -