Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><br /> For reference, I have found how to make @LostInComputer 's code work for areas as well. The class used for an area must implement <code>IRouteWithArea</code> for <code>context.Routes.Add</code> to work in an area's <code>RegisterArea</code> method. <br /><br /> Here's a generic class that can be used for areas (it extends the above <code>SEOFriendlyRoute</code> class):</p> <pre><code>public class AreaSEOFriendlyRoute : SEOFriendlyRoute, IRouteWithArea { private readonly string _areaName; // constructor: public AreaSEOFriendlyRoute(string areaName, string url, RouteValueDictionary defaults, IEnumerable&lt;string&gt; valuesToSeo, RouteValueDictionary constraints = null, RouteValueDictionary dataTokens = null, IRouteHandler routeHandler = null) : base(url, defaults, valuesToSeo, constraints, dataTokens, routeHandler) { this._areaName = areaName; } // implemented from IRouteWithArea: public string Area { get { return this._areaName; } } } </code></pre> <p><br /> ...and its' usage:</p> <pre><code>public override void RegisterArea(AreaRegistrationContext context) { context.Routes.Add("Example", new AreaSEOFriendlyRoute( areaName: this.AreaName, url: "my-area/{action}/{id}", valuesToSeo: new string[] { "action", "controller" }, defaults: new RouteValueDictionary(new { controller = "MyController", action = "MyDefaultPage", id = UrlParameter.Optional })) ); } </code></pre> <p><br /> Note that I am passing an extra argument when calling <code>context.Routes.Add</code>, which is defined as <code>areaName</code>. The formal parameter of the same name in the constructor is used to return this value from the <code>Area</code> method, in which is implemented from <code>IRouteWithArea</code>. <br /><hr /> So a link such as:</p> <pre><code>@Html.ActionLink("my link text", "MyJumbledPageName", "MyController", new { area = "MyArea" }, null) </code></pre> <p><br /> ...would result in the url <code>my-area/my-jumbled-page-name</code>. Also note that the preceding "<code>my-area</code>" in the url is obtained by hard-coding this in the route's <code>url</code> argument. <br /></p>
    singulars
    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. VO
      singulars
      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