Quantcast
Channel: Quickstep IT » ASP.Net MVC
Viewing all articles
Browse latest Browse all 4

ASP.NET Html.RenderPartial cannot convert void Error

$
0
0

Microsoft Visual Studio Development 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

Be Sociable, Share!

    The post ASP.NET Html.RenderPartial cannot convert void Error appeared first on Quickstep IT.


    Viewing all articles
    Browse latest Browse all 4

    Trending Articles