ASP.Net MVC Outbound Route Matching Problem When Using ActionLink

Posted by Godders on Stack Overflow See other posts from Stack Overflow or by Godders
Published on 2010-06-16T09:48:51Z Indexed on 2010/06/16 10:02 UTC
Read the original article Hit count: 313

Filed under:
|
|

Hi there,

Hoping for some help after reading into MVC routing and not coming up with the answer myself.

I have the following routes registered:

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

        routes.MapRoute(
            null,
            "YourFeedback/Article/{resourceId}",
            new { controller = "YourFeedback", action = "Index", contentTypeId = new Guid(ConfigurationManager.AppSettings["ArticleLibraryId"]) });

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

I have the following ActionLink in an aspx view:

<%=Html.ActionLink("Your Feedback", "Article", "YourFeedback", new
 {
     resourceId = Model.ContentId.ResourceId
 }, new { @class = "yourFeedback" })%>

My understanding of MVC routing is that this would render a anchor link with href of "/YourFeedback/Article/101" where 101 comes from Model.ContentId.ResourceId.

Yet the anchor link href is rendered as "YourFeedback/Article/resourceId=101".

Any ideas where I'm going wrong?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about routing