Search code examples
c#asp.net-corenuget

How to return view from another project in ASP NET Core?


I have a simple controller method for testing purpose like this:

[HttpGet]
public IActionResult Test()
{
    return View("SomeView");
}

Assume that I want to create a NuGet package that returns view with name SomeView, but this view can be implemented by user of my NuGet package. How can I do this? Is this possible?


Solution

  • You are really asking two separate questions here. One is about accessing views that aren't in the same project as the controller, and a second question about creating a Nuget package.

    1. Have a read of this SO answer to see how to access views in another project.

    2. Once you are comfortable with that, then you can turn that other project into a Nuget package. There are loads of articles around explaining how to do that. If you have a specific problem doing that, start a new question here.