English 中文(简体)
ASP. NET MVC 2条途径没有妥善解决(或我认为应该如何解决)
原标题:ASP.NET MVC 2 route not resolving properly (or, rather, how I think it should)

我从来就不需要尝试以下路线,即用户可以访问另一个主页或自己的(行政)主页。 这里是我拥有的路线:

    routes.MapRoute(null, "Home/Me",
        new { controller = "Home", action = "Admin" });
    routes.MapRoute(null, "Home/{userID}",
        new { controller = "Home", action = "Visitor" });

显然,我错误地认为,“Home/6e982cc5-4d1d-4232-947b-835e54e49c7”将在家庭控制人问题上采取下列行动:

public ActionResult Visitor(Guid userID) {}

没有人会说,为什么不像我这样工作?

最佳回答

2. 假设下列路线:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        null, 
        "Home/Me",
        new { controller = "Home", action = "Admin" }
    );

    routes.MapRoute(
        null, 
        "Home/{userID}",
        new { controller = "Home", action = "Visitor" }
    );

    routes.MapRoute(
        "Default",
        "{controller}/{action}/{id}",
        new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}

Home/4>将解决<代码>Visitor的操作问题,的控制器将作出例外规定,因为4不是<编码>><<<>>>>>>>>><<>>>>>>>>>>>><>>>>><>>>>>><<>>><>>>>>><>>><>>><>>>>><>>><>><>>>>>>>>>><>>>>><>>><>>>>><><>>>>>>>>>>>>>>>>>>>>>>>><>>>>>>>>>>>>>>>>>>>>><>>>>><

另一方面,<代码> Home/6e982cc5-4d1d-4232-947b-835e54e49c7 应当工作。 <代码>Home/Me将解决<代码>Admin关于控制器的行动。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签