不能隐式地将 void 类型转换为 object. NET MVC PartialViewResult

我有以下控制器操作:

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


return PartialView(actions);
}

以及下面的操作链接(使用 t4MVC 和剃刀语法)

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

然而,这给了我一个错误:

无法将 void 类型隐式转换为 object

据我所知,控制器的操作是正常的,那么是什么导致了这个错误呢?

88266 次浏览

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.

Difference between Html.RenderAction and Html.Action

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

Html.Partial should work as well :)

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

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

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