2

I have added a area called blogging in my site I created all the stuffs and I just tried to access it in the browser by manually entering the Url but I am getting error like "Server Error in '/' Application.". I have attached the code and snapshot of my project. Any help would be appreciated.

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 });
        }
    }
}

Folder Structure:

Architecture

Error:

Browser Error

4

3 に答える 3

2

UrlParameter.Optional の前に「id =」を追加して、id パラメータがオプションであることを指定します。

new {action="Index", id = UrlParameter.Optional }
于 2013-09-04T06:46:24.800 に答える
1

このURLにアクセスすればうまくいくと思います:

http://localhost:51803/Blogging/BloggingHome/Index/0

その理由は、MapRoute パラメータの指定が間違っているためです。これを指定しました:

new {action="Index", UrlParameter.Optional });

ID 名を含めるのを忘れたので、MVC は何を意味するのかわかりません。あなたはこれを求めている:

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

「id=」に注意してください。これは、id がオプションであることを MVC に伝えます。それがなければ、MVC は UrlParameter.Optional の意味を認識できないため、ID が必要になります。また、URL に ID が含まれていないため、ルートが選択されず、404 が発行されました。

于 2013-09-04T06:51:25.910 に答える
0

エリア登録をこれに更新して試してみませんか?

context.MapRoute("Blogging_default", "Blogging/{controller}/{action}/{id}", new {controller = "BloggingHome",action="Index",UrlParameter.Optional });
于 2013-09-04T04:35:52.450 に答える