I have heard that you can use views in a class library now in MVC5.
However I can't seem to find any guide on how to actually do this.
I have created a web app, created a class library and installed the MVC package in that library. I have a controller and a view in the library and I have referenced the library from the web app. This doesn't work and to be honest I didn't expect it to. It feels like I'm missing another link that ties my app to the view in my library.
How do I get the app to look in the library for views?
Using ASP.NET Core Razor Views from a Class Library - CodeOpinion Here's how you can use ASP.NET Core Razor Views and Layouts that are located in a class library (or netstandard library) from your MVC project. Skip to main content
In a previous post we explored the new View Component feature of ASP.NET Core MVC. In today’s post we take a look at how view components can be implemented in a separate class library and shared across multiple web applications.
Class based views are simpler and efficient to manage than function-based views. A function based view with tons of lines of code can be converted into a class based views with few lines only. This is where Object Oriented Programming comes into impact. Illustration of How to create and use create view using an Example.
In today’s post we take a look at how view components can be implemented in a separate class library and shared across multiple web applications. First, add a a new .NET Core class library to your solution. This is the class library where we will add our view components but before we can do that we have to add a reference to the MVC and Razor bits.
Here is a good blog post that will show you how:
http://www.danielroot.info/2013/07/reuse-mvc-views-using-virtual-path.html
Or you can use the Razor Generator project from codeplex:
http://razorgenerator.codeplex.com/
In order to get intellisense you need to make sure you have a web.config in the folder with the views.
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