Controller rename in core 1.1 results in 404 error

105 Views Asked by At

In a working Core 1.1 web app I renamed a controller. The controller url is invoked from a bootstrap popover in the code snippet :

    $('.main-select').on('shown.bs.popover', function () {
        $('.submit').click(function () {
            var fromval = $('.popover #fromvalue').val();
            var toval = $('.popover #tovalue').val();
            var option = {
                url: "/ProductMixController/GetDateData?dStart=" + fromval + "&" + "dEnd=" + toval,
                data: JSON.stringify({ dStart: fromval, dEnd: toval }),
                method: 'post',
                dataType: 'json',
                contentType: 'application/json;charset=utf-8'
            };

            window.location.href = option.url;

The original controller name was ProductMixSS and worked as expected. In order to follow the MS naming conventions I renamed it to ProductMixController. The result has been a consistent 404 error. The controller and model code are unchanged, all caches have been cleared - the ones I'm aware of, even NuGet - spellings have been checked and double checked, config files have been checked, port numbers have been changed and even the box has been rebooted.

I've seen some references to this 'bug' but don't appear to address the same problem I'm seeing.

So WTF.

1

There are 1 best solutions below

1
On

The problem is that under long-standing MVC rules and regulations a controller class is required to have "Controller" suffix in its name to route to the similarly named action. If you're not following this convention by coding your own routing you will run into the same issue. .Net Core has loosened this reg somewhat and it is now possible to place model, controller, view files as desired. However it seems putting the "Controller" suffix in the class name still follows the original MVC compile and execution path.

Wow. This was a two day exercise in befuddlement.