映射路线& ASP.NET MVC中的参数

时间:2010-03-29 21:07:46

标签: asp.net asp.net-mvc

在区域VIPUsers中,我有控制器ProfileController和其他控制器。

如果我希望ProfileController中的每个方法都有参数(id) 和其他控制器中的每个方法都有参数(userid和id) 我该如何映射呢?

是不是

context.MapRoute(
  "ProfileMapping",
  "VIPUsers/Profile/{action}/{id}",
  new {controller="ManageUsers", id=""}
);

然后为所有控制器映射默认值?

context.MapRoute(
  "Default",
  "VIPUsers/{controller}/{action}/{userId}/{id}",
  new {action="Index", userId="", id = ""}
);

并且......就是这样?我觉得它有效,但后来很奇怪......

如果我转到ProfileController上的页面并在{action}(VIPUsers / Profile / SomeAction / 4/4 /)之后给它两个参数,它将使用第二个映射路径。这是对的吗?

感谢

如果我希望url始终需要UserId,我该如何指定?

1 个答案:

答案 0 :(得分:1)

您看到的行为是正确的。您将需要实现一些路由约束以进一步缩小范围:

http://www.asp.net/learn/mvc/tutorial-24-cs.aspx