Vaccano
Vaccano

Reputation: 82291

Reusable UI in ASP.NET MVC

My company is standardizing on 3 different development models for our client code (we use web services for the business layer code):

  1. ASP.NET MVC
  2. SharePoint 2010
  3. WPF

Our goal is to be able to make changes and new apps quickly via re-use. I have done a lot of research into WPF and SharePoint 2010. WPF has Prism and SharePoint has WebParts (both of these allow reuse of UI components).

But we are planning to send a fair amount of the development to the ASP.NET MVC methodology. Much of this work will have common UI pieces. Since I have not done much research on ASP.NET MVC, I am hoping someone out there can enlighten me.

How is UI reuse done in ASP.NET MVC? (Meaning what is the Prism or WebParts of ASP.NET MVC?)

Upvotes: 2

Views: 1928

Answers (2)

Tom Clarkson
Tom Clarkson

Reputation: 16174

The first part of sharing UI between projects is the controllers, which is easy enough - inherit from a base controller in your shared library, and all the actions in that will work as if they were defined in each project.

You also need views of course, which is a bit harder. You need to either copy the view files into each project or set them up as embedded resources. It takes a bit of work to set up, but it can be done - see Views in separate assemblies in ASP.NET MVC

Upvotes: 1

mare
mare

Reputation: 13083

In MVC you have Partials. Partial controls (ASCX files) that you can render via various means:

  1. RenderPartial(controlname),
  2. RenderAction(action, controller), prepare the data in the controller action and then return the view with this data,
  3. if it's just HTML or JS that you want to reuse and render out, you also have an option of HTML Helpers,

and then with Razor View Engine that comes in MVC 3 there will be new options like Layouts and Sections.

Upvotes: 2

Related Questions