1

In my index.cshtml file I'm trying to render a partial view, but I'm having some problems doing this with inline razor syntax.

The following works and renders the partial view:

@{ Html.RenderPartial("_View", Model.model); }

The following gives an error:

@Html.RenderPartial("_View", Model.model)

The error is:

Argument 1: cannot convert from 'void' to 'object'

Is there something I'm misunderstanding about inline code in razor?

Kake_Fisk
  • 1,107
  • 11
  • 22
  • 2
    `RenderPartial()` is a void, using `@` you instruct Razor to print it. [You can't print void. You need `@Html.Partial()`, which returns an `IHtmlString` that can be printed](https://learn.microsoft.com/en-us/aspnet/core/mvc/views/partial). – CodeCaster Feb 07 '17 at 11:55
  • Possible duplicate of [cannot implicitly convert type void to object. .NET MVC PartialViewResult](http://stackoverflow.com/questions/4927586/cannot-implicitly-convert-type-void-to-object-net-mvc-partialviewresult) – CodeCaster Feb 07 '17 at 11:55
  • The suggested duplicate is the same problem, but does not contain an answer to the problem, although it contains the solution. What CodeCaster said is the answer. – Kake_Fisk Feb 07 '17 at 12:10
  • Both comments are mine. There is no question in your question, so I picked the duplicate that applies most. – CodeCaster Feb 07 '17 at 12:15

0 Answers0