无法从.cshtml标签运行应用程序

时间:2014-04-19 05:44:18

标签: c# asp.net-mvc asp.net-mvc-4 razor

我来到这里的奇怪问题。我使用Visual Studio 2012.当我从.cshtml选项卡开始调试我的Web应用程序时出现此错误

  '/'应用程序中的服务器错误。无法找到资源。

     

描述:HTTP 404.您正在寻找的资源(或其中一个   依赖项)可能已被删除,其名称已更改,或者是   暂时不可用。请查看以下网址并确认   拼写正确。

     

请求的网址:/Views/Header/GeneralInputs.cshtml

     

版本信息:Microsoft .NET Framework版本:4.0.30319;   ASP.NET版本:4.0.30319.225

当我从.cs标签运行时,一切都很好,运行良好。怎么了?

这是我的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 = "Header", action = "GeneralInputs", id = UrlParameter.Optional }
            );
        }
    }

此外,我尝试将此行添加到WebConfig,但这没有帮助

 <modules runAllManagedModulesForAllRequests="true" />

UPD:

我得到了什么 HeaderController

 public ActionResult GeneralInputs()
        {
            return View();
        }

3 个答案:

答案 0 :(得分:2)

我认为您无法像这样请求此页面:请求的网址/Views/Header/GeneralInputs.cshtml。您应该请求Header/GeneralInputs。您必须在控制器中请求Action。没有控制器中的视图

答案 1 :(得分:1)

您看到的功能实际上非常有用:直接运行光标所在的页面(Controller / Action)。

但是当您经常从View或需要参数的Actions调用它时,您可以从Project | Properties | Web修复起点,然后检查(o) Specific Page选项。

答案 2 :(得分:0)

操作名称“GeneralInputs”应位于 HeaderController 中,而 GeneralInputs.cshtml 文件应位于标题查看文件夹。如果两者都很好。然后在光标位于 GeneralInputs.cshtml 页面时不要运行您的应用程序。将光标保持在控制器中,然后运行您的应用程序。