c# - 区域注册在 MVC Razor 中不起作用

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

我在我的网站中添加了一个名为博客的区域,我创建了所有内容,我只是尝试通过手动输入网址在浏览器中访问它,但我收到了类似“'/'应用程序中的服务器错误”之类的错误。我已附上我的项目的代码和快照。 任何帮助,将不胜感激。

Global.Asax

public static void MyCustomRouting(RouteCollection coll)
{
    coll.IgnoreRoute("{resource}.axd/{*pathInfo}");
    coll.MapRoute("Default", "{controller}/{action}", new { controller = "Home", action = "Index" }, new[] { "Areas.Controllers" });
}

protected void Application_Start()
{
    //RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
    AreaRegistration.RegisterAllAreas();
    RegisterGlobalFilters(GlobalFilters.Filters);
    MyCustomRouting(RouteTable.Routes);
}

BloggingAreaRegistration.cs

using System.Web.Mvc;

namespace MVC_PageRouting.Areas.Blogging
{
    public class BloggingAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get { return "Blogging"; }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute("Blogging_default", "Blogging/{controller}/{action}/{id}", new {action="Index",UrlParameter.Optional });
        }
    }
}

文件夹结构:

Architecture

错误:

Browser Error

最佳答案

通过在 UrlParameter.Optional 前面添加“id =”来指定您的 id 参数是可选的

new {action="Index", id = UrlParameter.Optional }

关于c# - 区域注册在 MVC Razor 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18605435/

相关文章:

asp.net-mvc - 如何防止用户导航回上一页?

c# - ASP.NET MVC 3 - 仅在某些浏览器上重定向循环

c# - 如何在 c# 中覆盖或创建括号 "[]"的自定义行为?

c# - Controller 类包含太多方法

jquery - 在 jquery 对话框中显示 ASP MVC View

javascript - 更改 EventSouce 事件名称在 asp.net 中不起作用

css - 如何允许在网页中水平滚动

c# - 接口(interface)或继承类的 ASP.NET MVC3 编辑器模板

c# - 通过代码使用 Anchor Presets 定位 UI 元素

c# - 如何确定对象的大小,c#?