cannot implicitly convert type void to object. .NE

2019-03-12 00:52发布

问题:

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?

回答1:

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.



回答2:

Html.Partial should work as well :)

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


回答3:

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

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



回答4:

Difference between Html.RenderAction and Html.Action

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