2

I am a newby and working on the Solutions Developer Course for Sitecore 8.2 online in Visual Studio with Sitecorerocks. Also just a heads up, very recently I had to rebuild this Visual Studio 2015 solution due to a corrupted .csproj file. So my question is:

Why am I getting this error message when trying to create a new Controller Rendering for SubscribeForm. It is setup to use a tested placeholder I have used for many other control renderings and there is no model associated since I am just trying to display the initial route(Index).

Error Message: enter image description here

Sitecore Explorer: Created Controller rendering: enter image description here

Sitecore Explorer: Presentation Rendering and place holders are setup like this for an events detail page:

enter image description here

Solution Explorer: Controller:

Controller:

Solution Explorer: Views/SubscribeForm/Index.cshtml:

enter image description here

3
  • Are the other controllers that are working as expected in the same namespace? Commented Dec 19, 2018 at 21:29
  • Yes all the controllers are in the same namespace.
    – ACronin
    Commented Dec 19, 2018 at 22:14
  • @AndreaCronin ever get past this? Commented Dec 17, 2019 at 0:00

3 Answers 3

4

There are a couple of potential issues here:

  • Set the controller name to the fully qualified class name, e.g MyProject.Controllers.SomeController, MyProject
  • Make sure the action name does not have the / in, it should just be Index
  • It looks like you have not registered your controller with the IoC container. Sitecore 8.2 introduced a lot of new Dependency Injection features. But this meant that you would now have to register your controller with the container for Sitecore to be able to create it.

Registering your Controller

The easiest way to do this would be to create a Configurator class that implements IServicesConfigurator, and register your controller in there. Here is an example

using Microsoft.Extensions.DependencyInjection;
using Sitecore.DependencyInjection;

namespace MyProject
{
    public class Configurator: IServicesConfigurator
    {
        public void Configure(IServiceCollection serviceCollection)
        {
            serviceCollection.AddTransient<MyController>();
        }
    }
}

Then you have to create a patch include file that will tell Sitecore to use that Configurator. Here is an example of that:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <services>
            <configurator type="MyProject.Configurator, MyProject" />
        </services>
    </sitecore>
</configuration>

Once you have that setup, Sitecore will now know how to create your controller correctly.

1

You shouldn't need the / before the action name in your rendering. Change /Index to Index and it should work properly.

4
  • Thank you for your help, I removed the / before the action name and still getting the same error.
    – ACronin
    Commented Dec 19, 2018 at 21:21
  • Can you try renaming the post action in your controller? I wonder if Sitecore is getting confused about which action to use. Commented Dec 19, 2018 at 21:28
  • I just renamed it, I have even tried deleting the httpost section all together before, and this error still keeps occurring. To me it feels like, It can't even find/interact with the controller at all.
    – ACronin
    Commented Dec 19, 2018 at 22:09
  • Can you try renaming the controller? Commented Dec 20, 2018 at 11:08
-2

Try putting the full type name of the controller in the highlighted field:

events.tac.local.Controllers.SubscribeFormController,events

enter image description here

(Make sure that the assembly name is events or update it.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.