Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested master pages using Razor syntax

I'm trying to get nested master pages working with the new razor syntax. Any help appreciated:

The error I'm getting is

Execute() no suitable method found to override

Delving further I have my _Site.cshtml, which is the main master page and inherits ViewMasterPage.

My nested master page is _layout.cshtml, which uses _site as a layout, uses some helpers and inherits from ViewMasterPage

I have a _ViewStart.cshtml, which points to my Layout file.

And finally I have my index page which inherits from ViewPage

So at the top of each page I have:

Site:

@inherits System.Web.Mvc.ViewMasterPage

Layout

@inherits System.Web.Mvc.ViewMasterPage<MyMasterViewModel>
@{ Layout ="~/Views/Shared/_Site.cshtml"; }

ViewStart

@{ Layout ="~/Areas/AreaName/Views/Shared/_Layout.cshtml"; }

Index

@inherits System.Web.Mvc.ViewPage<MyHomeModel>

Any ideas???

Cheers!

like image 410
Sniffer Avatar asked Apr 02 '26 01:04

Sniffer


1 Answers

ViewMasterPage is used for WebForms views.
Razor layout pages do not inherit a special class; instead, they inherit the same ViewPage class.

You should use the @model directive instead of @inherits in all three pages.

like image 131
SLaks Avatar answered Apr 04 '26 15:04

SLaks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!