2013-08-19 74 views
0

我有一个mvc项目。在项目中,我添加名称的新区域BEK 它创建BEKAreaRegistration.cs本身将区域添加到mvc项目

public class BEKAreaRegistration : AreaRegistration 
{ 
    public override string AreaName 
    { 
     get 
     { 
      return "BEK"; 
     } 
    } 

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

和我的Global.asax文件是如下

protected void Application_Start() 
    { 
     AreaRegistration.RegisterAllAreas(); 

     RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
     RouteTable.Routes.IgnoreRoute("{*allAspx}", new { allAspx = @".*\.aspx(/.*)?" }); 
     RouteTable.Routes.IgnoreRoute("{*allAsmx}", new { allAsmx = @".*\.asmx(/.*)?" }); 
     RouteTable.Routes.IgnoreRoute("{*allAshx}", new { allAshx = @".*\.ashx(/.*)?" }); 
     RouteTable.Routes.IgnoreRoute("Services/{*pathInfo}"); 
     RouteTable.Routes.IgnoreRoute(""); 

     RouteTable.Routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
     ); 
    } 

但是当我试图转到BEK /主页/索引页面我得到错误页面。我还应该做什么

无法找到资源。 描述:HTTP 404.您正在查找的资源(或其某个依赖项)可能已被删除,名称已更改或暂时不可用。请检查以下网址并确保它拼写正确。

请求的URL:/ LMS_WEB_APP/BEK /主页


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

这是我想的问题是,你有两个和应用同名控制器的方式

回答

0

错误。像你有主控制器在正常应用和区域 而且,它导致相同控制器的重复声明。

的方式做的就是指定控制器的命名空间像下面这样:

public override void RegisterArea(AreaRegistrationContext context) 
{ 
    context.MapRoute(
    "BEK_default", 
    "BEK/{controller}/{action}/{id}", 
    new { action = "Index", id = UrlParameter.Optional }, 
    new string[] { "MyAppName.Areas.BEK.Controllers" } // specify the new namespace 
); 
} 

如果没有的话,请发表你所得到的错误消息。

+0

,当我把断点到这条线就嗟这是问题是不是这个 – brtb

+0

可以请你,邮政您的错误信息! –

+0

我为它坏的粘贴而感到抱歉 – brtb

0

当您添加BEK区域。 MVC将为您创建这些。

enter image description here

的mvc不会产生任何控制器和操作和视图。

因此,您必须手动执行以下操作:添加哪些控制器,操作和视图。

因此,现在您必须通过右键单击控制器并添加控制器来添加控制器。

添加控制器后。

你可以做的动作右击并添加视图这样添加的视图:

enter image description here

好吧.... 所以,你有两个控制器和行动和意见需要。

现在您可能需要解决控制器备份问题,如果有的话,我早先已经告诉您。

快乐Coading ...