MVC 3 - 新区 - 404错误 - 未找到资源 - 试图航线调试 [英] MVC 3 - New Area - 404 error - Resource not found - have tried route debugger

查看:190
本文介绍了MVC 3 - 新区 - 404错误 - 未找到资源 - 试图航线调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的MVC 3应用程序 - 的演示地面位。
我有一个地区和多数民众一直正常工作。

I have a small MVC 3 app - bit of a demo ground. I have one area and thats been working fine.

我刚才说的另一个领域期望只是旋转起来的应用程序,它的工作 - 但没有,404 - 资源无法找到

I have just added another area expecting to just spin up the app and it work - but no, 404 - The resource cannot be found.

在AreaRegistration的地图路线是默认的(这是我创建的第一个区域)。

The map route in the AreaRegistration is the default (as is the first area i created).

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

我曾尝试添加了特定的控制器到这个,但没有。

I have tried adding in a specific controller into this, but nothing.

所以,我下载菲尔哈克的RouteDebugger并在打字时,我的路由发现的http://服务器/明信片/制作(这是我想太)

So I downloaded Phil Haack's RouteDebugger and my route is found when typing in http://server/Postcard/Create (which is where I am trying to get too)

该区域的结构

我的控制器

    public class CreateController : Controller
{
    private ILogger Logger { get; set; }
    private ICardSender Emailer { get; set; }
    private IOCCardRepository CardRepository { get; set; }

    public CreateController(ILogger logger, ICardSender cardSender, IOCCardRepository repository)
    {
        this.Logger = logger;
        this.Emailer = cardSender;
        this.CardRepository = repository;
    }


    //
    // GET: /Postcard/Create/

    public ActionResult Index()
    {
        var model = new OCPostcardModel().Create();

        return View(model);
    }

现在:因为我已经删除了整个区域,试图再次没有工作。所以我在特定的控制器中添加的路由(内部AreaRegistration文件)

NOW: I have since deleted the entire area, tried again it didn't work. So I added in the specific controller in the route (Inside AreaRegistration file)

context.MapRoute(
            "Postcard_default",
            "Postcard/{controller}/{action}/{id}",
            new { controller = "Create", action = "Index", id = UrlParameter.Optional }
        );

和它的工作...我不知道为什么我以前这样做的时候没有工作,但现在是。

And its working...I don't know why it didn't work when I did this before, but it is now.

不过奇怪的是,虽然我从来没见过有人在此控制器加入到航线中的任何演示的我看的 - 我还没有得到它在我的其他地区

Still curious though as I've not seen anyone add in this controller into route in any of the demo's i've looked at - and I haven't got it in my other area?

推荐答案

我遇到了这个,当我提出一个控制器到一个区域,但忘了更新命名空间。控制器名称的作用范围是该地区的命名空间。因此,一些,在区域将映射到App.Areas.Area.Controllers.SomeController,这是不存在的。

I ran into this when I moved a controller into an Area but forgot to update the namespace. The controller name is scoped to the Area's namespace. So "Some" in "Area" will map to App.Areas.Area.Controllers.SomeController, which didn't exist.

这篇关于MVC 3 - 新区 - 404错误 - 未找到资源 - 试图航线调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆