Search code examples
asp.net-mvcuser-interfacecode-reusereusability

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?)


Solution

  • 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.