【发布时间】:2018-06-11 15:15:41
【问题描述】:
我已经解决这个问题一段时间了,但我不确定还有什么可以尝试的。我收到的错误消息是这样的:
System.InvalidOperationException:未找到视图“索引”或其主视图,或者没有视图引擎支持搜索的位置。搜索了以下位置:
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Home/Index.cshtml
~/Views/Home/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
视图位于Views/Home/Index.cshtml
这是RouteConfig 类
public class RouteConfig {
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
即使在 Home 控制器的 Index 操作中设置断点也不会触发。 Index 控制器操作只返回视图:
public ActionResult Index() {
return View("~/Views/Home/Index.cshtml");
}
项目设置设置为Use Local IIS Web server
构建项目成功。没有构建事件。目标框架是 .NET Framework 4.5。输出类型是类库。
我正在将我能想到的一切与另一个正在运行的项目进行比较,但没有什么对我来说很突出。我什至比较了两者的.csproj 文件,唯一的区别似乎是不在其他项目中的文件的<Content Include 行。有什么想法可以解决这个问题吗?
【问题讨论】:
-
这可能很傻,但你确定你在运行而不是发布时处于调试状态吗?
-
@MichaelPuckettII 在这一点上,我会接受所有“可能很愚蠢”的问题,因为我必须遗漏一些东西。要回答您的问题,是的,它在调试配置中。只是因为,我也尝试过发布配置,同样的错误。