C# – The controller for path ‘/’ was not found or does not implement IController


I'm working on a piece of code that shows a random sponsor image on each webpage. I figured that the best place to call my function is in the Views/Shared/_Layout.cshtml page, because that's the one that loads at every page.

I wrote the function in a service class in my domain model, and wrote a ChildActionOnly function in my homecontroller, returns the value in a simple view in Views/Home/Randomsponsor.cshtml and called the function in the shared layout with a Html.action.

Everything builds fine, but while running i get the next error:

{"The controller for path '/' was not found or does not implement IController."}

Does anyone know how to fix this one?

Method in the domain project:

public String advertsForCountry()
    String studentSchool = finder.getLoggedStudent().SchoolId;
    int studentCountry = db.Schools.Find(studentSchool).CountryId;

    List<Sponsor> sponsorsForStudent = new List<Sponsor>();
    List<Advert> adverts = db.Adverts.ToList();
    foreach(Advert adv in adverts)
        foreach(Country cntry in adv.Countries)
            if(cntry.CountryId == studentCountry)
    Random random = new Random();
    int randomSP = random.Next(0, sponsorsForStudent.Count()-1);
    string sponsorAdvert = sponsorsForStudent.ElementAt(randomSP).SponsorCompany;
    return sponsorAdvert;       

In HomeController:

public ActionResult RandomSponsor()
    var model = service.advertsForCountry();

    return PartialView("RandomSponsor", model);

Simple view in Views/Home/ :

    ViewBag.Title = "RandomSponsor";


And my function call in the View/Shared/_Layout.cshtml whitch contains the navigation bar, etc:

@Html.Action("RandomSponsor", "HomeController")


Best Solution

(Converted from comment)

You don't need to specify the full class name of the Controller in Html.Action. Try using @Html.Action("RandomSponsor", "Home") instead of @Html.Action("RandomSponsor", "HomeController").