Kevin Main
Kevin Main

Reputation: 2344

ASP.NET MVC Templated Control

I am currently building an ASP.NET MVC site after years of being in the Web Forms world (and taking a bit of getting used to!).

I have an admin dashboard which has several area's contained in boxes which can be collapsed etc. The basic layout of the box is the same for all - the only difference is the content inside the box. I don't really want to repeat the box code over and over (talking only about front end code here). What I would normally do in the Web Forms world is create a control with template region for the content (i.e http://weblogs.asp.net/scottgu/archive/2006/06/04/Supporting-Templates-with-ASP.NET-User-Controls.aspx)

This question is pretty similar to my scenario How do build a composite or template control in ASP.Net MVC, or the equivelant?. The top answer in the referenced question points to this article http://jeffreypalermo.com/blog/asp-net-mvc-and-the-templated-partial-view-death-to-ascx/ which I guess would work but seems somewhat of a hack. What is the best way to achieve this in MVC? How do others handle this?

Upvotes: 1

Views: 891

Answers (1)

Aliostad
Aliostad

Reputation: 81660

If the sharing is in the layout, use master (a concept from web forms).

If it is in the content then use Display/Editor Templates.

Upvotes: 1

Related Questions