Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在ASP.Net core 2.1 Web API中将控制器视图设置为默认页面?_C#_Asp.net Web Api_Asp.net Core Webapi_Asp.net Core 2.1 - Fatal编程技术网

C# 如何在ASP.Net core 2.1 Web API中将控制器视图设置为默认页面?

C# 如何在ASP.Net core 2.1 Web API中将控制器视图设置为默认页面?,c#,asp.net-web-api,asp.net-core-webapi,asp.net-core-2.1,C#,Asp.net Web Api,Asp.net Core Webapi,Asp.net Core 2.1,在ASP.NET web应用程序框架中,对于web API,我可以通过更改以下代码来创建网站的默认页面: routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); App_Star

在ASP.NET web应用程序框架中,对于web API,我可以通过更改以下代码来创建网站的默认页面:

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
App_Start文件夹的RouteConfig.cs。
但在ASP.NETCore2.1应用程序框架的WebAPI中,如何将MVC控制器的视图设置为默认页面?没有名为RouteConfig.cs的文件

它是在
Configure
方法中的Startup.cs中配置的:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    ....
    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "Default",
            template: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = 1 });                    
    });
}

为什么您希望在Web API中查看?Web API控制器方法是否返回视图?不Web API控制器方法只返回状态或数据。@TanvirArjel除了VS生成的项目文件夹结构之外,Web API和Web应用之间真的有什么区别吗?