Cristian Boariu
Cristian Boariu

Reputation: 9621

Strange MVC issue

I am having trouble with the following code:

@Html.RenderPartial("_SortDisplayPage", new ViewDataDictionary { { "bottomClass", "pagingBottom" } })

It gives the error:

Cannot implicitly convert type void to object

I think it's something small but cannot find it...

Upvotes: 12

Views: 6748

Answers (2)

Zain Ali
Zain Ali

Reputation: 15953

The RenderPartial() call renders its result directly to the response object and cannot be used like a simple string.

All you have to do is enclose the call in a code block.

@{Html.RenderPartial("TopNavigation");}

Upvotes: 6

tvanfosson
tvanfosson

Reputation: 532445

You want @Html.Partial not RenderPartial. RenderPartial writes directly to the response and doesn't return a value. Partial returns an MvcHtmlString, which the @ operator will write to the response.

Upvotes: 29

Related Questions