Search views in the callee Project

BanKid 20 Reputation points
2023-08-31T12:28:19.02+00:00

Hello,

From my main MVC application, i am trying to call a controller action that is located in a second MVC project. I can call the controller action, but i am getting the error:

The view 'myLogin.cshtml' or its master was not found or no view engine supports the searched locations. The following locations were searched:

~/Views/Account/myLogin.cshtml.aspx

~/Views/Account/myLogin.cshtml.ascx

~/Views/Shared/myLogin.cshtml.aspx

~/Views/Shared/myLogin.cshtml.ascx

~/Views/Account/myLogin.cshtml.cshtml

~/Views/Account/myLogin.cshtml.vbhtml

~/Views/Shared/myLogin.cshtml.cshtml

~/Views/Shared/myLogin.cshtml.vbhtml

It seems that the engine looks for the view in my main (the caller) project. How can i let it look in the folders of the second (the callee) project?

Thanks in advance

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

Accepted answer
  1. Bruce (SqlWork.com) 57,646 Reputation points
    2023-08-31T17:13:22.1466667+00:00

    the easiest fix is to add a msbuild step that copies the views in project2 to the main project view folder.

    if you want a seperate folder in the main site, you would create a custom view engine and add view search templates for the new folder. You may need to update the publish step to include this folder.

    note: in net 6+ razor page views (not mvc views) can be compiled into a library.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. QiYou-MSFT 4,306 Reputation points Microsoft Vendor
    2023-09-01T08:17:24.8333333+00:00

    Hi @BanKid

    The reason for this is that CSHTML files do not translate well into DLLs. I offer you a plan:

    I offer you a plan:

    1.Install RazorGenerator

    Case1

    2.Create a new class library. Also add references to System.Web, System.Web.Helpers, System.Web.Mvc, System.Web.WebPages.

    If you do not add a reference, you will have the following error:

    Picture2

    3.Create a folder View-Share. At the same time, you need to rename the newly created html file to cshtml and finally reference RazorGenerator.

    Case2

    4.Referenced in another project: RazorGenerator.MVC.

    Picture3

    Best regards,

    Qi You


    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.

    0 comments No comments