【发布时间】:2022-01-11 08:27:27
【问题描述】:
我对 .NET Core 相当陌生,曾在 Windows 窗体等较旧的 .NET 版本上工作过。我在_Layout 页面中设置了一个导航栏,我想用它来重定向到其他 Razor 页面。
例如,我在 Views 文件夹之外的名为 Home 的文件夹中有一个 Home 页面 (index.cshtml)。如果我想从导航栏中选择客户搜索选项,我会使用 onclick 事件来调用下面的函数。
function SearchClick() {
window.location.href = "CustomerSearchView.cshtml";
return false;
}
CustomerSearchView 位于Views 中Home 文件夹下的CustomerSearch 文件夹中。还有一个CustomerSearchController有代码
public IActionResult Index()
{
return View();
}
如果我尝试将路径添加到浏览器中,例如https://localhost:7022/CustomerSearchView.cshtml,则会出现错误
找不到这个 localhost 页面 - 没有找到该网址的网页:https://localhost:7022/CustomerSearchView.cshtml
我已经尝试了使用Views/CustomerSearch 和其他人的完整路径的各种变体,但得到了同样的错误。
我不熟悉路由过程,我不确定自己犯了什么错误,我认为这样可以节省时间询问,如果有人能指出这一点,我会非常高兴。
【问题讨论】:
标签: redirect asp.net-core-mvc razor-pages