2
votes

I'm currently working on an ASP.NET Core 2.1. RC1 Final (May 2018) demo application. I try to use the new Razor UI Library in my ASP.NET Core MVC application.

Thus, in my Solution I have 2 Projects:

  1. ASP.NET Core MVC application
  2. Razor Class Library

The structure of my Razor Class Library is very simple:

  • RazorClassLib1
    • Areas
      • MyFeature
        • Pages: Page1.cshtml

The cshtml of Page1.chtml looks like that:

@page
@model RazorClassLib1.MyFeature.Pages.Page1Model
@{
    Layout = "_Layout";
}

<h1>Hello From the Razor ClassLib1</h1>

Now I want to use this Page1.cshtml Razor component in my MVC View. This feature would be useful to organize and reuse razor pages within my application.

Unfortunately I have no idea how to achieve this. I was following this example:

http://www.talkingdotnet.com/asp-net-core-2-1-razor-ui-as-class-library/

though it seems to work only for a razor page project, but I would need it in my MVC projct.

Do you know how to use a Razor Class Library in ASP.NET MVC Core 2.1. Views?

Thank you very much.

1
Have you seen the documentation from Microsoft =>blogs.msdn.microsoft.com/webdev/2018/03/01/…CodeNotFound
I have repeated what you have done (MVC, Razor Libray). Added reference (from MVC to razor library). And it works. The thing which is not mentioned in the article is that the address is (iisexpres) localhost:port/myfeature/page1. See the Build 2018 video What's new in Web Development with ASP.NET Core 2.1 20:30.IvanH

1 Answers

0
votes

https://gunnarpeipman.com/aspnet/razor-class-library-mvc/

explains how to set it up.

There are some things to know: Controllers must have AreaAttribute Web application must have area route defined.

I think there work arounds using the areas, but I am researching this myself. will update the answer when I have figured it out.

Below link also explains how to make the area name dynamic: https://blog.tech-fellow.net/2018/11/11/razor-ui-class-library-with-dynamic-area-name/