0

I have a component whose assigned controller does not have an Index method. This is intentional, as the controller action is set to a specific action method.

Regardless, Sitecore still attempts to invoke the Index method and errors out because there is none:

Could not invoke action method: Index. Controller name: Training. Controller type: {client name}.Website.Controllers.{client name}.Components.TrainingController

I've double checked the Controller and Controller Action component rendering settings are pointing the right place, and both these properties are properly assigned: (This was configured by someone else)

Controller: {client name}.Website.Controllers.{client name}.Components.TrainingController Controller Action: TrainingListingComponent

The assigned action TrainingListingComponent:

public ActionResult TrainingListingComponent()
{
    var rendering = RenderingContext.Current.Rendering;
    var allItems = rendering.GetAllItemsFromFieldValue("Training Items");
    var model = CreateTrainingListModel(rendering.Parameters["Single Column"] == "1", allItems);
    model.RenderingItemId = rendering.Item.ID.Guid;            

    return View(GetViewDirectory("PageElements", "TrainingListingComponent"), model);
}

Am I missing an additional setting? Are there special requirements of controller which do not contain Index methods? Please assist.

  • Looks correct. And while this is not a proper fix, if you added an empty index() method to the controller, does the code then execute the right method without an error? – Jarmo Jarvi Jul 6 '17 at 16:54
  • Try, not fully qualifying your controller definition. So just "Training" as opposed to Client.Website.etc.TrainingController. – Mark Cassidy Jul 6 '17 at 16:56
  • Adding an empty Index() produces a C# error since the method returns no value. – thiirteen Jul 6 '17 at 17:26
  • Can you try to change the value in the controller field to have the entire namespace of your controller followed by the dll name. for eg Controller: {client name}.Website.Controllers.{client name}.Components.TrainingController, dll name – adarsh Jul 7 '17 at 6:24
  • Are you sure that there are no additional route definitions in your project? Try search (ctrl+shift+F) for "Route" and check if there is anything defining a new route with an Index method as default or just hard-coded. – Andrey Bobrov Jul 7 '17 at 6:27
0

The solution ended up being something along the lines of Andrey Bobrov's suggestion:

Are you sure that there are no additional route definitions in your project? Try search (ctrl+shift+F) for "Route" and check if there is anything defining a new route with an Index method as default or just hard-coded. I had defined a JSON service route that implemented the same path as the page I was tying to access. Changed the service route solved the issue quickly.

| improve this answer | |

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