Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC3 View Inheritance not possible?

I want to create an abstract base view (with lots of virtual methods with cshtml) and then create a derived view that optionally overrides these methods to customise the view:

for example:

override void Header(string title) {
 <div class="massive">@title</div>
}

How can this be achieved with razor?

(doesn't everybody want/need to do this?)

like image 389
Jack Avatar asked Sep 01 '11 12:09

Jack


1 Answers

I believe you would be better off using Helper methods than trying for an inheritance model on views. Use Scott Gu's blog for an introduction:

http://weblogs.asp.net/scottgu/archive/2011/05/12/asp-net-mvc-3-and-the-helper-syntax-within-razor.aspx

http://www.asp.net/mvc/tutorials/creating-custom-html-helpers-cs

like image 145
AdamCrawford Avatar answered Sep 20 '22 14:09

AdamCrawford