6

is it possible to add a single Controller and possibly a view or two, in a class library ... which could then be redistributed (ie. via NuGet) and reused in various applications?

I'm thinking of providing a default view (or two) but allowing the consumer to override this view via a public property.

Possible?

Pure.Krome
  • 84,693
  • 113
  • 396
  • 647

1 Answers1

2

There is nothing built-in ASP.NET MVC 3 allowing you to embed views into class libraries (controllers, yes, but not views). It is necessary to write a custom VirtualPathProvider. Here's a blog post which might put you on the right track. And you could also take a look at MVCContrib portable areas which allows you to do this.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • How about defining a route, to a controller .. where the controller exists in a referenced class library? Lets assume that the view is not embedded in the class library and is defined via properties. – Pure.Krome Feb 27 '11 at 10:38
  • @Pure.Krome, having a controller which resides in a different assembly is possible. Just define a controller in a separate assembly, reference this assembly in your web application and it should work. – Darin Dimitrov Feb 27 '11 at 11:06