David Lee
David Lee

Reputation: 861

No overload for method 'RenderPartial' takes 3 arguments

This is driving me crazy, i am getting:

No overload for method 'RenderPartial' takes 3 arguments

a compresed version of my _layout:

    <head>
    @{
      var footer = new footer(User);
      var pageTitle = ViewData["Title"].ToString();
    }
    </head>
    <body>
        @{ 
            Html.RenderPartial(
                  "_footer",
                   footer,
                   new ViewDataDictionary(this.ViewData) { { "pageTitle", pageTitle } }
            );
        }
    </body>

in my shared _layout, i am trying to pass a model to the partial view and a string which is provided by ViewData not sure what is going on.

i am setting title from the page _mypage.cshtml that uses that layout:

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewData["Title"] = "My Title";
}
<h1>Hello there</h1>

_footer is a partial view where i am using the footer object and also calling other partial view where i need the title.

Upvotes: 0

Views: 994

Answers (1)

Charles Cavalcante
Charles Cavalcante

Reputation: 1618

You can do it using ViewBag.

MyController.cs:

// set the title on a ViewBag inside your action
ViewBag.pageTitle = "My Title"; 

_layout.cshtml:

// call your partial view passing the model
@Html.Partial("footer", footer); 

_footer.cshtml:

<!-- use the ViewBag data with @ -->
<h1>@ViewBag.pageTitle</h1> 

Upvotes: 2

Related Questions