views:

39

answers:

2

Hi.

I am using the following code in my master page:

<%  Html.RenderAction("RecentArticles","Article"); %>

where the RecentArticles Action (in ArticleController) is :

[ChildActionOnly]
    public ActionResult RecentArticles()
    {
        var viewData = articleRepository.GetRecentArticles(3);

        return PartialView(viewData);
    }

and the code in my RecentArticles.ascx partial view :

<li class="title"><span><%= Html.ActionLink(article.Title, "ViewArticle", new { controller = "Article", id = article.ArticleID, path = article.Path })%></span></li>

The problem is that all the links of the articles (which is built in the partial view) lead to the same url- "~/Article/ViewArticle" . I want each title link to lead to the specific article with the parameters like I'm setting in the partial view.

Thanks.

+1  A: 

I think your not using the ActionLink correctly. Change the ActionLink code to:

Html.ActionLink(
    article.Title,
    "ViewArticle",
    "Article",   // put the controller here
    new
    {
        id = article.ArticleID,
        path = article.Path 
    },
    null)

Notice the null at then end.

EDIT: Why are you using [ChildActionOnly] in your controller? Since it is an MVC 2 feature I am assuming that you are using MVC2? Try removing it and check out the following article:

http://www.davidhayden.me/2009/11/htmlaction-and-htmlrenderaction-in-aspnet-mvc-2.html

I think the issue has to do with your partial not rendering. I would start by just trying to verify that your partial is rendering properly. Once you confirm that start to debug why the partial is not outputing.

Kelsey
Hi Kelsey, and thanks, but it didn't help. I've also noticed that whatever I put inside the partial view, like add a div with content, it doesn't get rendered into the browser, I keep getting the list of recent articles, with the links all wrong. I'm starting to think maybe the view isn't rendered at all and what's showing is just the RecentArticles action. Please correct me if I'm wrong ...
olst
A: 

I was able to solve the problem by using the following call in my RecentArticles action:

return PartialView("~/Views/Shared/Article/RecentArticles.ascx", viewData);

It seems like the partial view was not being rendered at all,

Thanks !

olst