BikerP
BikerP

Reputation: 878

Html.RenderAction - the controller for path '/' was not found

Using ASP.NET MVC 2 and and Html.RenderAction in my masterpage implemented as below throws an error with "the controller for path '/' was not found":

I'm a bit of a newbie, do i have to do something in RegisterRoutes to make this work?

<% Html.RenderAction("TeaserList", "SportEventController"); %>

public class SportEventController : Controller
{
    public string TeaserList()
    {
        return "hi from teaserlist";
    }
}

Upvotes: 0

Views: 4234

Answers (2)

M4N
M4N

Reputation: 96606

I'm not sure but I guess the following things are wrong:

  • your TeaserList method should return an ActionResult
  • the call to RenderAction should be RenderAction("TeaserList", "SportEvent") without the Controller suffix

Upvotes: 7

Jonathan Bates
Jonathan Bates

Reputation: 1835

In order for that to work, TeaserList() has to be a method that returns an ActionResult like:

`
public virtual ActionResult TeaserList()
    {
        return View();
    }

`

If you want "Hi from teaserlist" then you could have that in a View called TeaserList or you could add

`ViewData["teaserList"] = "hi from teaserlist";`

and have it rendered in your view.

Upvotes: 0

Related Questions