views:

91

answers:

2

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";
    }
}
A: 

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.

Jonathan Bates
it doesn't have to return a ActionResult, returning a string works just fine...try it and see!
While that is true (in essence, your controller turns all pubic methods into Actions anyway), I believe the spirit is to return ActionResults, and that way (for testing, as example) you could return any subtype. So in your case, you could return a ContentResult.
Jonathan Bates
A: 

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
M4N
i will crawl back into my shell, it was the "Controller" suffix, thanks Martin ...BTW: it doesn't have to return a ActionResult, returning a string works just fine...try it and see!
Thanks for the feedback!
M4N