Search views in the callee Project

BanKid 20 Reputation points


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:









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

A Microsoft web application framework that implements the model-view-controller (MVC) design pattern.
987 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce ( 44,546 Reputation points

    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 3,306 Reputation points Microsoft Vendor

    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


    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:


    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.


    4.Referenced in another project: RazorGenerator.MVC.


    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