I have several ASP.NET MVC 3 Web applications that have a lot of common objects:
web.config
files.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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With