1

I added these routes to RouteConfig.cs

routes.MapRoute(
    name: "NewPositiveRelease",
    url: "dispatch/{poNumber}/{article}",
    defaults: new { controller = "PositiveReleaseItem", action = "Create"});
routes.MapRoute(
    name: "Dispatch",
    url: "dispatch",
    defaults: new { Controller = "Dispatch", action = "Index"});

In the hopes that I could go to this url

locahost:3000/dispatch/4529707272/171112

To execute the Create action in PositiveReleaseItemController. However, when I navigate to that url, I am seeing the error:

A public action method '4529707272' was not found on controller 'MVCQCPage.Controllers.DispatchController'.

Can someone please help me understand why this doesn't work?

Here is the controller:

using SharedLibrary.Models;
using System.Web.Mvc;

namespace MVCQCPage.Controllers
{
    public class PositiveReleaseItemController : Controller
    {
        // GET: PositiveReleaseItem
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Create(string poNumber, string article)
        {
            return View();
        }
        public ActionResult Insert(PositiveReleaseItem item)
        {
            return View();
        }
    }
}

I tried changing the order of the given routes, but with the same outcome. Please let me know if I can add any details which might help.

Thanks

Bassie
  • 9,529
  • 8
  • 68
  • 159

2 Answers2

1

Shouldn't it be:

"PositiveReleaseItem/{poNumber}/{article}",

Instead of:

"dispatch/{poNumber}/{article}",
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • 1
    This was actually related to the ordering of routes. I put my 2 new routes at the top of `RouteConfig.cs` and it now works fine.. Not sure why though – Bassie Jul 03 '17 at 04:45
  • 1
    oh yeah that... its tripped me up a few times too: https://stackoverflow.com/a/27478227/495455 anyway glad to hear its working! – Jeremy Thompson Jul 03 '17 at 04:51
1

I was able to resolve this by simply placing my new route mappings at the top of Routeconfig.cs (above all the others).

Not sure why this worked, as none of my other route maps refer to the Dispatch controller, so its weird that it was complaining about that.

Bassie
  • 9,529
  • 8
  • 68
  • 159
  • I'm glad you didn't mark this as correct, let's see what [so] members in the future can work out based on your initial diagnosis. – Jeremy Thompson Jul 03 '17 at 08:09
  • 2
    If a *more* generic route appears before your own, like the fefault `{controller}/{action}/{id}` it will be chosen. The route configuration is just a list of routes, it doesn't try to solve overlapping routes and assign priorities. – Panagiotis Kanavos Jul 03 '17 at 08:42