C# “ASP.NET核心”;此本地主机页可以’;“找不到”;

C# “ASP.NET核心”;此本地主机页可以’;“找不到”;,c#,asp.net,asp.net-core,C#,Asp.net,Asp.net Core,当尝试测试我的应用程序时,我使用vs2017获得“找不到此本地主机页”。 试图达到 这是我的Startup.cs public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method

当尝试测试我的应用程序时,我使用vs2017获得“找不到此本地主机页”。
试图达到
这是我的Startup.cs

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseMvc();
    }
}

根据您共享的代码,您需要使用属性路由显式地提供路由

public class ProjectenEnPersoneelCONTROLLER : Controller
{
    [Route("Test/Test")]
    public IActionResult Index()
    {
        var webClient = new WebClient();
        var json = webClient.DownloadString(@"D:\Users\tijnv\source\repos\API_STA_1\API_STA_1\Json\test-request.json");
        var projects = JsonConvert.DeserializeObject<Projects>(json);
        return View(projects);
    }
}
公共类ProjectenEnPersoneelCONTROLLER:Controller
{
[路线(“测试/测试”)]
公共IActionResult索引()
{
var webClient=新的webClient();
var json=webClient.DownloadString(@“D:\Users\tijnv\source\repos\API_STA_1\API_STA_1\json\test request.json”);
var projects=JsonConvert.DeserializeObject(json);
返回视图(项目);
}
}
或者,您可以将控制器重命名为TestController,并将操作方法重命名为TestController

public class TestController : Controller
{

    public IActionResult Test()
    {
        var webClient = new WebClient();
        var json = webClient.DownloadString(@"D:\Users\tijnv\source\repos\API_STA_1\API_STA_1\Json\test-request.json");
        var projects = JsonConvert.DeserializeObject<Projects>(json);
        return View(projects);
    }
}
公共类TestController:Controller
{
公共IActionResult测试()
{
var webClient=新的webClient();
var json=webClient.DownloadString(@“D:\Users\tijnv\source\repos\API_STA_1\API_STA_1\json\test request.json”);
var projects=JsonConvert.DeserializeObject(json);
返回视图(项目);
}
}

app.UseMVC()中没有路线模板的原因是什么?也是在启动应用程序或尝试导航到该页面时?@JamesS我没有更改此文件的任何内容,因此我不知道为什么没有路由模板。这是我启动应用程序的时候,因为我更改了启动url。要测试/测试而不是显示[“value1”、“value2”]的api/值,请显示控制器代码。@DeepakMishra您是指ValuesController吗?我的意思是[测试/测试]行动。这确实有些作用,但似乎不起作用。它正在一个名为Views的文件夹中查找Test.cshtml@T.v.A.您可以在视图构造函数中提供路径作为第一个参数,第二个参数作为模型
返回视图(“Views/Home/Index.cshtml”,project)
谢谢您的帮助!我现在可以看到测试,但我有一个不同的错误,你能帮我吗?仅使用Model尝试foreach,而不是Model.products,您还可以通过添加断点来检查属性是否存在并且它是IEnumerable。当我删除.projects时,我得到错误:foreach语句无法对“projects”类型的变量进行操作,因为“projects”不包含“GetEnumerator”的公共实例定义