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

C#asp.net Mvcasp.net Mvc-3T4mvc

C# Problem Overview


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?

C# Solutions


Solution 1 - C#

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.

Solution 2 - C#

Html.Partial should work as well :)

@Html.Partial("View", Model);

Solution 3 - C#

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

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

Solution 4 - C#

https://stackoverflow.com/questions/2955261/difference-between-html-renderaction-and-html-action

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMrBlizView Question on Stackoverflow
Solution 1 - C#Darin DimitrovView Answer on Stackoverflow
Solution 2 - C#VladLView Answer on Stackoverflow
Solution 3 - C#EwaldView Answer on Stackoverflow
Solution 4 - C#AhmedView Answer on Stackoverflow