Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange MVC issue

Tags:

asp.net-mvc

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...

like image 231
Cristian Boariu Avatar asked Jan 07 '12 14:01

Cristian Boariu


2 Answers

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.

like image 158
tvanfosson Avatar answered Nov 16 '22 02:11

tvanfosson


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");}

like image 6
Zain Ali Avatar answered Nov 16 '22 03:11

Zain Ali