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

时间:2022-02-04 16:34:32

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)

以及以下操作链接(使用t4MVC和razor语法)

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

However this gives me the error:

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

cannot implicitly convert type void to object

不能隐式地将类型void转换为对象

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

就我所知控制器动作是ok的,那么什么会给我这个错误呢?

4 个解决方案

#1


108  

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


25  

Html.Partial should work as well :)

Html。部分也可以:)

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

#3


10  

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

我也有同样的问题。对我有用的是将表达式封装在花括号中。

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

@ { Html。RenderPartial方法(“viewName”模型);}

#4


3  

Difference between Html.RenderAction and Html.Action

Html的区别。RenderAction和Html.Action

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

不同的事情有不同的目的。查看上面的链接。

#1


108  

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


25  

Html.Partial should work as well :)

Html。部分也可以:)

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

#3


10  

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

我也有同样的问题。对我有用的是将表达式封装在花括号中。

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

@ { Html。RenderPartial方法(“viewName”模型);}

#4


3  

Difference between Html.RenderAction and Html.Action

Html的区别。RenderAction和Html.Action

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

不同的事情有不同的目的。查看上面的链接。