ASP.Net MVC的路由映射 [英] ASP.Net MVC route mapping

查看:114
本文介绍了ASP.Net MVC的路由映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的MVC(和ASP.Net路由)。我试图映射的.aspx *一个叫控制器的PageController

  routes.MapRoute(
   页,
   (名称)的.aspx
   新{控制器=页面,行动=索引,ID =}
);

岂不的code上面的图*的.aspx到的PageController ?当我运行这一点,键入任何.aspx页面中我得到以下错误:


  

为路径/Page.aspx控制器无法找到或没有实现的一个IController接口。
  参数名:controllerType


有什么我不是在这里做什么?


解决方案

  

我刚才已经回答我的问题。我有
  向后路由(默认值是
  以上页)。


是的,你必须把默认路由首先定制路由。


  

因此​​,这带来了下一个问题......
  请问在默认路由匹配(我
  假设他们使用常规的前pressions
  这里)页面路线?


根据我们称之为约定优于配置默认的路由匹配。斯科特格思里解释了它很好在ASP.NET MVC他的第一个博客帖子。我建议你​​阅读它也是他的其他职务。请记住,这些是基于所述第一CTP发布,框架已经改变。您还可以找到关于ASP.NET MVC网络直播由斯科特Hanselman的的asp.net网站。

I'm new to MVC (and ASP.Net routing). I'm trying to map *.aspx to a controller called PageController.

routes.MapRoute(
   "Page",
   "{name}.aspx",
   new { controller = "Page", action = "Index", id = "" }
);

Wouldn't the code above map *.aspx to PageController? When I run this and type in any .aspx page I get the following error:

The controller for path '/Page.aspx' could not be found or it does not implement the IController interface. Parameter name: controllerType

Is there something I'm not doing here?

解决方案

I just answered my own question. I had the routes backwards (Default was above page).

Yeah, you have to put all custom routes above the Default route.

So this brings up the next question... how does the "Default" route match (I assume they use regular expressions here) the "Page" route?

The Default route matches based on what we call Convention over Configuration. Scott Guthrie explains it well in his first blog post on ASP.NET MVC. I recommend that you read through it and also his other posts. Keep in mind that these were posted based on the first CTP and the framework has changed. You can also find web cast on ASP.NET MVC on the asp.net site by Scott Hanselman.

这篇关于ASP.Net MVC的路由映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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