Any examples of MVC 4.7 calling razor class library component view?

iqworks Information Quality Works 196 Reputation points
2022-05-07T23:27:58.647+00:00

I have an MVC 4.7 MVC project. I created a .net 5.0 razor class library with the default component. Now I need to access that component from my MVC 4.7 MVC project to display this components own page to come up.
Not sure how to do that. I see many examples of MVC core accessing razor class library components. Perhaps I just didn’t search correctly.
Thanks for any advice or suggestions

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,148 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Zhi Lv - MSFT 32,011 Reputation points Microsoft Vendor
    2022-05-09T01:45:38.05+00:00

    Hi @iqworks Information Quality Works ,

    First, the .net 5.0 razor class library is based on the .NET but the Asp.net 4.7 MVC is based on the .NET Framework, you can't add the .net 5.0 razor class library to the 4.7 MVC project. About the difference between them, see Compare ASP.NET Core and ASP.NET.

    Second, the .net 5.0 razor class library is a class library, when using it, you need to add the class library to an Asp.net (5/6) Razor page or MVC application, then in the 4.7 MVC project, you can call the Asp.net 5 (I assume you will create an Asp.net 5 Razor page application and add the class library) project's razor page/view via the http request and get the response.

    Here are some relates articles about using Razor class library:

    Create reusable UI using the Razor class library project in ASP.NET Core

    Working with Razor Class Libraries in ASP.NET Core

    Then, in the 4.7 MVC application, you can use JQuery ajax or HttpClient to call the Asp.net 5 project's page/views.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    0 comments No comments

  2. iqworks Information Quality Works 196 Reputation points
    2022-05-09T16:44:23.013+00:00

    Hi, thanks for the info. I will look at your links today. I have been searching all around for an answer to this question. But if what you are saying is true, bummer. I REALY dont
    want to migrate to .net 5.0. The analyzer basically said "dont be fool, to much work :-)".

    0 comments No comments

  3. iqworks Information Quality Works 196 Reputation points
    2022-05-11T14:11:53.52+00:00

    Hi Dillion, it looks like i might be able to use .Net Standard to call .Net core 5.0 razor class library?


  4. iqworks Information Quality Works 196 Reputation points
    2022-05-12T02:27:03.79+00:00

    thanks for getting back.
    so i guess i have to migrate my .net 4.7 to .net 5.0 in order to access a razor class library?
    i think i have to make a call to the specific component, but i cannot do this from .net 4.7?
    i thought .net standard would allow me to access all of the BCL api's that are used by .net framework, .net core and ther whole .net ecosystem? no?


  5. iqworks Information Quality Works 196 Reputation points
    2022-05-12T16:00:42.84+00:00

    thanks ZhiLv,
    There have one way: you can create an Asp.net 5 project and add the razor class library, then host and run the project. Then, in the .Net 4.7 project, you can call the hosted website and access the page via the http request.

    I will try this on my next pass at this project and will let you know how it went.

    Thanks so much

    0 comments No comments