Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot implicitly convert type void to object. .NET MVC PartialViewResult

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?

like image 919
MrBliz Avatar asked Feb 07 '11 22:02

MrBliz


4 Answers

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.

like image 89
Darin Dimitrov Avatar answered Nov 04 '22 08:11

Darin Dimitrov


Html.Partial should work as well :)

@Html.Partial("View", Model);
like image 44
VladL Avatar answered Nov 04 '22 07:11

VladL


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

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

like image 41
Ewald Avatar answered Nov 04 '22 08:11

Ewald


Difference between Html.RenderAction and Html.Action

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

like image 6
Ahmed Avatar answered Nov 04 '22 07:11

Ahmed