Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that you don't have a route that matches the route values (controller = Home, action = Create).</p> <p>You have two routes, one is the empty string (no parameters), which matches Controller = "Home", Action = "Index". The other is your hash route, which matches Controller = "Home", Action = "RequestLink". So, when ASP.Net Routing goes to build a URL from the route values you're providing, it can't find one (since none of them have the "{controller}" and "{action}" parameters).</p> <p>The simplest solution, in this case, is to create a direct route to the "Create" action, so that you can still use your "hash" route. Put this at the top of your RegisterRoutes method. NOTE: Order <em>does</em> matter! ASP.Net Routing checks each route, in the order added, until it finds a match.</p> <pre><code>routes.MapRoute( "Create", // Route name "Create", // URL with parameters new { controller = "Home", action = "Create" } // Parameter defaults ); </code></pre> <p>Since you have that "hash" route, you can't really use the default "{controller}/{action}/{id}" technique, since the "hash" value would be consider a valid Controller name. So, if someone requested: <a href="http://www.mysite.com/fjhas82" rel="nofollow noreferrer">http://www.mysite.com/fjhas82</a>, MVC would look for a Controller called "fjhas82" and complain that it couldn't find it. Unfortunately, this means you have to manually add new routes for each new Controller Action (like I showed above), which is a pain. </p> <p>The best solution (in my opinion) is to use Regex Constraints: If your hashes have a very well-defined format (say: 5 letters followed by 2 numbers, or "_" followed by any alpha-numeric characters, etc.), or if you're willing to impose such a format, you can use the Regex constraints supported by ASP.Net Routing. Then, you'd only need these two routes</p> <pre><code>routes.MapRoute( "Redirect", "{hash}", new { controller = "Home", action = "RequestLink" }, new { hash = @"[a-zA-Z]{5}[0-9]{2}" } // Regex Constraints ); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index" } // Parameter defaults ); </code></pre> <p>Under these routes, if MVC sees a controller name like: "Home", it will check the first route, find that it doesn't match the regular expression, and move to the next one. NOTE: My Regular Expression syntax may be a bit rusty, so I'd use something like <a href="http://regexpal.com/" rel="nofollow noreferrer">http://regexpal.com/</a> to test a Regex first, to make sure it works with your hashes and controller names.</p> <p>Hope that helps, I know I wrote a lot, but MVC is so flexible, you can do things in so many different ways!</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. 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