asp.net-web-api - MVC 结合 ASP.NET Core 中的 Web API,但是 View 在哪里?

标签 asp.net-web-api asp.net-core asp.net-core-mvc

我正在努力了解新的 ASP.NET Core 1.0,它指出 ASP.NET Web API 和 ASP.NET MVC 被合并到一个框架中。因此,我决定使用 Visual Studio 2015 中的 ASP.NET Web API 模板创建一个新的 ASP.NET Core Web API 应用程序。

但是当我查看生成的文件/文件夹时,没有 Views 文件夹。生成了 ValuesController。我什至添加了我自己的 Controller ,它返回 Web API 响应。但是我也应该能够在我的 Controller 中添加操作,比如返回部分 View ,对吗?

由于这两个已合并,我假设我应该能够看到 Views 文件夹,但我没有。如何将 MVC 部分添加到使用 Web Api 模板创建的应用程序?

最佳答案

您可以按照以下步骤手动添加 Views 文件夹:

  1. 创建一个 Views 文件夹。
  2. Views 文件夹中创建 _ViewStart.cshtml,内容如下:
@{
  Layout = "_Layout";
}
  1. Views 文件夹中创建一个 Shared 文件夹。
  2. Shared 文件夹中创建 _Layout.cshtml,内容如下:
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - Web App</title>

</head>
<body>

    @RenderBody()

</body>
</html>

关于asp.net-web-api - MVC 结合 ASP.NET Core 中的 Web API,但是 View 在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41971676/

相关文章:

c# - VS Enterprise 负载测试发起 IP 地址

asp.net - 如何使用 HttpClient 将 Json 数据作为参数传递给 web api

asp.net-web-api - 如何在.net web api中将DateTime对象作为json传递

asp.net-mvc - wwwroot 服务页面不是 MVC6

asp.net-core - 为什么我不应该使用 IFormFile 进行大型上传

http - 是否可以使用 ASP.NET WebApi 为 HEAD 响应设置 Allow header ?

c# - 在 AngularJS $http 中传递日期到 ASP.NET Web Api

webpack init 尝试使用不受支持的 extract-text-webpack-plugin

c# - AspNet.Security.OpenIdConnect.Server。刷新 token

asp.net - 包含 ASP.net 5 内容的 Nuget 包