English 中文(简体)
PA. Network MVC 3 - 困难理解路线
原标题:ASP.NET MVC 3 - Difficulty understanding Routes

I ve在MVC 3上建立了一套系统,将NerdDinner tutorial作为开工基地。 我不相信我完全理解鲁廷。

一切工作都经过了罚款。 我给感化助手增加了一种。

这里指的是全球。

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

    routes.MapRoute(
        "UpcomingKeyDates", // Route name
        "KeyDates.mvc/{sortBy}/Page/{page}", // URL with parameters
        new { controller = "Home", action = "Index" } // Parameter defaults
    );

    routes.MapRoute(
       "Default", // Route name
       "{controller}.mvc/{action}/{id}", // URL with parameters
       new { controller = "Home", action = "Index", sortBy = "EventDate" } // Parameter defaults
    );

    routes.MapRoute(
        "Root", // Route name
        "", // URL with parameters
        new { controller = "Home", action = "Index", sortBy = "EventDate" } // Parameter defaults
    );

}

我不想遗漏这份名单,以便最终确定在你首次到页(做罚款)时发生的日期。 这种类型和想象力也奏效。 然而,当Im利用这一联系时......

<%: Html.ActionLink("Create New", "Create", "Home") %>

链接仅指同一页。 是否需要增加一条新路线,或修改一条现有路线? 任何帮助都受到高度赞赏。

感谢。

最佳回答

缺省路线应始终如一,是一条总线。 它将自动赶上相当于“http://yourdomain.com/ 的空航路线。

缺省路线应始终采用以下格式:

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "foo", action = "bar", id=UrlParameter.Optional }
);

Also, if the page is going to be a number, you can constrain it using a regular expression (see below).

页: 1 委员会希望:

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

    routes.MapRoute(
        "UpcomingKeyDates", // Route name
        "KeyDates.mvc/{sortBy}/Page/{page}", // URL with parameters
        new { controller = "Home", action = "Index" }, // Parameter defaults
        new { page = @"d+" } // Note I have constrained the page so it has to be an integer...
    );

    routes.MapRoute(
       "MyDefaultRoute", // Your special default which inserts .mvc into every route
       "{controller}.mvc/{action}/{id}", // URL with parameters
       new { controller = "Home", action = "Index", id=UrlParameter.Optional, sortBy = "EventDate" } // Parameter defaults
    );

    routes.MapRoute(
       "Default", // Real default route. Matches any other route not already matched, including ""
       "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id=UrlParameter.Optional, sortBy = "EventDate" } // Parameter defaults
    );
}
问题回答

暂无回答




相关问题
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. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签