Image may be NSFW.
Clik here to view. Sometimes the simple things throw you a real curve ball when you are in a rush.
All I wanted today was to move a piece of menu code into a Razor partial view. I created the partial view layout and made the standard call in my main layout.
@Html.RenderPartial("TopNavigation")
The result was a compilation error: Cannot implicitly convert type ‘void’ to ‘object‘
The answer is oh, so simple.
The RenderPartial() call renders its result directly to the response object and cannot be used like a simple string result. All you have to do is enclose the call in a code block.
@{Html.RenderPartial("TopNavigation");}
And voilà, a rendered top menu that I can share across several layouts.
If this solution has helped you please let me know by leaving a comment below.
photo credit: shehan365 via photopin cc
The post ASP.NET Html.RenderPartial cannot convert void Error appeared first on Quickstep IT.