Note that there are some explanatory texts on larger screens.

plurals
  1. POHtml.ActionLink Including extra parameters
    primarykey
    data
    text
    <p>Using the following code:</p> <pre><code>@Html.ActionLink("News", "Index", new { controller = "News", area = "" }, new { @class = "News" }) </code></pre> <p>I'm getting an error so that when I'm on a particular news article, the link is generating as:</p> <p><a href="http://mywebsite/News/2011/12/2/my_slug" rel="nofollow">http://mywebsite/News/2011/12/2/my_slug</a></p> <p>where the parameters match the page that I'm currently on. The also happens on other controllers matching the same url schema (imagine I have another controller called Presentations that matches the url scheme of News entirely). From the presentations pages, a link to news would include the presentations parameters which aren't valid input for the news controller. Make sense?</p> <p>I have my routes defined as:</p> <pre><code> routes.MapRoute( "News-Archive", // Route name "News/Archive", // URL with parameters new { controller = "News", action = "Archive" }, // Parameter defaults new[] { "mywebsite.Controllers" } ); routes.MapRoute( "News-Stub", // Route name "News/{year}/{month}/{date}/{slug}", // URL with parameters new { controller = "News", action = "Index" }, // Parameter defaults new[] { "mywebsite.Controllers" } ); routes.MapRoute( "News-ByDay", // Route name "News/{year}/{month}/{day}", // URL with parameters new { controller = "News", action = "Archive" }, // Parameter defaults new[] { "mywebsite.Controllers" } ); routes.MapRoute( "News-ByMonth", // Route name "News/{year}/{month}", // URL with parameters new { controller = "News", action = "Archive" }, // Parameter defaults new[] { "mywebsite.Controllers" } ); routes.MapRoute( "News-ByYear", // Route name "News/{year}", // URL with parameters new { controller = "News", action = "Archive" }, // Parameter defaults new[] { "mywebsite.Controllers" } ); routes.MapRoute( "News-Default", // Route name "News", // URL with parameters new { controller = "News", action = "Index" }, // Parameter defaults new[] { "mywebsite.Controllers" } ); </code></pre> <p>Can someone please explain if the problem lies in my use of Html.ActionLink or my route definitions? </p> <p>EDIT:</p> <p>Changing the Actionlink to:</p> <pre><code>@Html.ActionLink("News", "Index", new { controller = "News", area = "", year = string.Empty, month = string.Empty, day = string.Empty, slug = string.Empty}, null) </code></pre> <p>results in this when called from a presentation page (those values are for the presentation, not a valid news item):</p> <p><a href="http://mywebsite/News?year=2011&amp;month=12&amp;slug=seo_overview" rel="nofollow">http://mywebsite/News?year=2011&amp;month=12&amp;slug=seo_overview</a> </p> <p>Not sure why that's causing the rewriting to change.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload