c# - 无法从 .cshtml 选项卡运行应用程序

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

我遇到了奇怪的问题。我使用 Visual Studio 2012。当我开始从 .cshtml 选项卡调试我的 Web 应用程序时,我收到此错误

Server Error in '/' Application. The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Views/Header/GeneralInputs.cshtml

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version: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" />

更新:

我得到了什么 标题 Controller

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

最佳答案

我认为您不能像这样请求此页面:请求的 URL/Views/Header/GeneralInputs.cshtml。您应该请求Header/GeneralInputs。您必须在 Controller 中请求操作。 Controller 中没有 View

关于c# - 无法从 .cshtml 选项卡运行应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23166374/

相关文章:

c# - 未找到 System.Security.Cryptography

asp.net-mvc - Asp mvc 4 成员资格和 Web 安全

c# - Entities Framework 6 alpha 2 - 异步模式

c# - 在 C++ (COM) Dll 导入中使用 C# 代码不太正确

c# - 在 div 的后台 url 中求值

asp.net-mvc - 开发 localhost 时禁用 Azure Active Directory

asp.net - 带有控制台应用程序的 Windows 调度程序 API 与带有 asp.net mvc 的 .net 调度程序工具,用于在我的 asp.net MVC 中执行长时间运行的进程

c# - 使用sendkey函数在C#中将键盘键发送到浏览器

c# - 压缩 XML 的最佳方式

asp.net-mvc - MVC Controller - Http Post 映射值