100

I have the following controller action:

[ChildActionOnly]
public virtual PartialViewResult ListActions(int id)
{
    var actions = meetingActionRepository.GetAllMeetingActions(id);

    return PartialView(actions);
}

And the following action link (using t4MVC and the razor syntax)

<p>
   @Html.RenderAction(MVC.MeetingActions.ListActions(Model.MeetingId))
</p>

However this gives me the error:

cannot implicitly convert type void to object

As far as i can tell the controller action is ok, so what could be giving me this error?

yoozer8
  • 7,361
  • 7
  • 58
  • 93
MrBliz
  • 5,830
  • 15
  • 57
  • 81

4 Answers4

137

Like this:

<p>
    @Html.Action(MVC.MeetingActions.ListActions(Model.MeetingId))
</p>

or if you insist on RenderAction like this:

<p>
    @{Html.RenderAction(MVC.MeetingActions.ListActions(Model.MeetingId));}
</p>

Personally I prefer the first, makes fewer keystrokes.

Ryan Lundy
  • 204,559
  • 37
  • 180
  • 211
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • 1
    Thank you. Funky syntax there. I assume that's the razor way of doing <%html instead of <%=Html ? What's the difference between Action and Renderaction anyway. Phil Haack says RenderAction is more efficient? – MrBliz Feb 07 '11 at 23:08
  • 2
    @Doozer1979, yeah, exactly, that's the Razor way. – Darin Dimitrov Feb 07 '11 at 23:09
  • 1
    This also works : {Html.RenderAction(MVC.MeetingActions.ListActions(Model.MeetingId));}, so using @ is not necessary. – FrenkyB Jul 01 '16 at 08:19
48

I had the same issue. What worked for me is to encapsulate the expression it in curly brackets.

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

Ewald
  • 698
  • 7
  • 10
  • This worked for me, however I have no idea why adding curling brackets would work. Can you elaborate on that? – Brad Thiessen Jun 12 '18 at 01:26
  • 2
    @BradThiessen It works because ASP.NET MVC is quite frankly a shoddy framework full of glaring holes and poor design decisions. I just came across this too. Who knows why, but my patience is wearing thin with MVC. – user9993 Jun 14 '18 at 14:40
  • 11
    @BradThiessen `RenderPartial()` is a void, using `@` you say the Razor to print it which is not possible as it doesn't produce any output content! – S.Serpooshan Sep 26 '18 at 14:44
45

Html.Partial should work as well :)

@Html.Partial("View", Model);
VladL
  • 12,769
  • 10
  • 63
  • 83
6

Difference between Html.RenderAction and Html.Action

Different things for different purposes. Check out the above link.

Community
  • 1
  • 1
Ahmed
  • 1,985
  • 1
  • 13
  • 8