Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing views between ASP.NET MVC 3 Web application projects

I have several ASP.NET MVC 3 Web applications that have a lot of common objects:

  • The same login controller. The few differences between their login systems are captured in their web.config files.
  • Header/detail views: invoices, payment orders, payment orders, etc.

In order to make my code less redundant, I moved common controllers and views to a separate class library (models were already in their own class libraries). After googling for a while, I eventually found out how to call controllers in external assemblies, however, I still don't know how to call views in external assemblies. How do I do that?

like image 533
pyon Avatar asked Jun 21 '11 19:06

pyon


People also ask

What is a view in MVC?

A view is an HTML template with embedded Razor markup. Razor markup is code that interacts with HTML markup to produce a webpage that's sent to the client. In ASP.NET Core MVC, views are.cshtml files that use the C# programming language in Razor markup. Usually, view files are grouped into folders named for each of the app's controllers.

What are the benefits of using an AspView component?

View components provide the same SoC that controllers and views offer. They can eliminate the need for actions and views that deal with data used by common user interface elements. Like many other aspects of ASP.NET Core, views support dependency injection, allowing services to be injected into views.

What is an application part in MVC?

An Application Part is an abstraction over the resources of an application, from which MVC features like controllers, view components, or tag helpers may be discovered. One example of an application part is an AssemblyPart, which encapsulates an assembly reference and exposes types and compilation references.

Can I use Visual Studio 2013 with ASP NET MVC?

You can use Visual Studio 2013 also with ASP.NET MVC 4 or 5 installed. If you are using older version of Visual Studio/ ASP.NET MVC then you need to create similar solution and be careful for small changes due to different version. Now let’s open up Visual Studio and start building demo.


1 Answers

You may want to look at MVCContrib Portable areas. They allow you to compile an entire MVC application area into one assembly, including controllers, views and supporting files such as JavaScript and CSS. I've worked on a large project that made extensive use of them and they work well, especially combined with T4MVC.

like image 102
Russ Cam Avatar answered Sep 20 '22 15:09

Russ Cam