【发布时间】:2019-01-27 22:39:48
【问题描述】:
我之前曾问过一个关于抛出 404 错误的问题,但感谢尝试帮助我调试的人们的帮助,我现在有一个更具体的问题要问。
我在加载任何调用@Html.Partial 的视图时看到以下错误:
This localhost page can’t be found
在 Visual Studio 中,我看到 return View() 被击中。
来自 HomeController 的示例方法:
[Route("")]
public ActionResult Welcome()
{
return View();
}
我正在使用 Microsoft.AspNet.MVC 版本 5.2.7 以防万一。
浏览器错误图片:
路由配置:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapMvcAttributeRoutes();
}
}
我的目录:
Welcome.cshtml:
@using Newtonsoft.Json
@{
Layout = null;
}
<!doctype html>
<html class="no-js" lang="">
<head>
<title>Test</title>
@Html.Partial("_HeadPartial")
</head>
<body>
<p></p>
</body>
</html>
_HeadPartial:
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
任何类型的部分引用:
@Html.Partial("_AnalyticsPartial")
给我上面的 404 错误;删除引用允许渲染成功。我的部分可以是空的,但仍然会导致 404。
为什么@Html.Partial 会造成这种情况?
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-partialview