无法使用绝对网址

时间:2016-06-19 04:29:15

标签: visual-studio-2015 asp.net-core

我在ASP.NET MVC Core RC2中使用VS2015。我在Controllers文件夹中有一个名为TestController的控制器,如下所示:

// GET: /<controller>/
        public IActionResult Index()
        {
            ViewBag.Mesage = "Test message";
            return View();
        }

名为TestRel.chtml的相应视图位于文件夹Views/Northwind内,如下所示:

@{
    <label>Test view</label>
}

但是,为了测试,当我运行绝对网址http://localhost:49944/Test/Index时,我收到以下错误

InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/Views/Test/Index.cshtml
/Views/Shared/Index.cshtml
Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable`1 originalLocations).

如何使用绝对网址显示上述视图

1 个答案:

答案 0 :(得分:0)

如果我使用return view("~/views/northwind/TestRel.cshtml");或将其放入views / test /,return view("testrel");

后它应该有效