简体   繁体   English

如何从 ASP.NET Core 中的另一个项目返回视图?

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

I have a simple controller method for testing purpose like this:我有一个简单的 controller 方法用于测试目的,如下所示:

[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?假设我想创建一个 NuGet package 返回名为SomeView的视图,但是这个视图可以由我的 NuGet package 的用户实现。我该怎么做? Is this possible?这可能吗?

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.一个是关于访问与 controller 不在同一个项目中的视图,第二个问题是关于创建 Nuget package。

  1. Have a read of this SO answer to see how to access views in another project.阅读此 SO 答案以了解如何访问另一个项目中的视图。

  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.一旦您对此感到满意,您就可以将其他项目变成 Nuget package。有很多文章解释了如何做到这一点。 If you have a specific problem doing that, start a new question here.如果您在这样做时遇到具体问题,请在此处开始一个新问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将View返回到.net核心Web应用程序中的另一个项目(模块) - How to return View into another project (modules) in .net core web application 如何从 ASP.NET Core MVC 中的一个控制器调用或返回另一个控制器的视图 - How to call or return the view of another controller from one controller in ASP.NET Core MVC 在ASP.NET核心中使用时,如何从另一个项目访问EF核心的DbContext? - How to I access the DbContext of EF core from another project when used in ASP.NET core? 发布时从另一个ASP.NET Core 2项目引用ASP.NET Core 2项目失败 - Referencing ASP.NET Core 2 project from another ASP.NET Core 2 project fails when publishing 从另一个项目初始化ASP.NET Core Web API - Initialize ASP.NET Core Web API from another project ASP.NET Core:从解决方案中的另一个项目访问appsettings - ASP.NET Core: Accessing appsettings from another project in solution 在 asp.net core 上使用来自不同项目的另一个控制器 - Use another controller from different project on asp.net core 在 asp.net 内核中看不到来自另一个项目的 DbContext - Cannot see the DbContext from another project in asp.net core 如何在 Asp.Net Core MVC 的 ExceptionFilter 中返回带有 model 的视图 - How return View with model in the ExceptionFilter in Asp.Net Core MVC 如何让 Asp.Net Core 返回正确的视图 - How to get Asp.Net Core to return the correct view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM