Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Views From a Class Library [duplicate]

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?

like image 788
Jon Avatar asked Feb 02 '14 19:02

Jon


People also ask

Can I use razor views from a class library?

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

Can view components be implemented in a separate class library?

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.

What is the difference between class based views and function based views?

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.

How do I implement a view component across multiple web applications?

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.


1 Answers

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.

like image 119
CD Waddell Avatar answered Sep 23 '22 11:09

CD Waddell