Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, you must disambigute your methods by giving them two different names:</p> <pre><code>public ActionResult DetailsGuid(Guid guid) { var model = Context.GetData(guid); return View(model); } public ActionResult DetailsString(string id) { var model = Context.GetData(id); return View(model); } </code></pre> <p>Next, you need a custom route handler to inspect the request, and change the method name accordingly:</p> <pre><code>using System.Web.Mvc; using System.Web.Routing; public class MyRouteHandler : IRouteHandler { public IHttpHandler GetHttpHandler(RequestContext requestContext) { var routeData = requestContext.RouteData; var stringValue = routeData.Values["id"].ToString(); Guid guidValue; var action = routeData.Values["action"]; if (Guid.TryParse(stringValue, out guidValue) &amp;&amp; (guidValue != Guid.Empty); routeData.Values["action"] = action + "Guid"; else routeData.Values["action"] = action + "String"; var handler = new MvcHandler(requestContext); return handler; } } </code></pre> <p>Finally, add a <code>Details</code> route at the top of your routes, as follows:</p> <pre><code>routes.Add("Details", new Route("{controller}/Details/{id}", new RouteValueDictionary( new { controller = "Home", action = "Details" }), new MyRouteHandler() ) ); ); </code></pre> <p>When a request comes in for details, the <code>Details</code> route will use your custom route handler to inspect the <code>id</code> token. The route handler adds to the action name based on the form of the id token, so that the request will be directed to the appropriate action.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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