question

iqworksInformationQualityWorks-8937 avatar image
0 Votes"
iqworksInformationQualityWorks-8937 asked iqworksInformationQualityWorks-8937 answered

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

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

dotnet-aspnet-core-razor
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ZhiLv-MSFT avatar image
0 Votes"
ZhiLv-MSFT answered ZhiLv-MSFT edited

Hi @iqworksInformationQualityWorks-8937,

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

iqworksInformationQualityWorks-8937 avatar image
0 Votes"
iqworksInformationQualityWorks-8937 answered iqworksInformationQualityWorks-8937 edited

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 :-)".

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

iqworksInformationQualityWorks-8937 avatar image
0 Votes"
iqworksInformationQualityWorks-8937 answered ZhiLv-MSFT commented

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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

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

I'm afraid we can't do that. Because the razor class library supports .net core 5.0, it is not compatible with .NetStandard.

You can also refer this article to learn: Create reusable UI using the Razor class library project in ASP.NET Core.

0 Votes 0 ·
iqworksInformationQualityWorks-8937 avatar image
0 Votes"
iqworksInformationQualityWorks-8937 answered ZhiLv-MSFT commented

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?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

so i guess i have to migrate my .net 4.7 to .net 5.0 in order to access a razor class library?

Yes. If you directly add the razor class library project reference in the .Net 4.7 project, it will show the compatibility error. Then, after migration the .net 4.7 application to asp.net 5.0, you can add the razor class library reference.

i think i have to make a call to the specific component, but i cannot do this from .net 4.7?

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.

0 Votes 0 ·
iqworksInformationQualityWorks-8937 avatar image
0 Votes"
iqworksInformationQualityWorks-8937 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.