尝试将函数返回到控制器的每个视图

时间:2022-10-21 22:16:44

I have the following function in my ProjectsController EDIT: i want to render this in _Layout.html

我的ProjectsController编辑中有以下函数:我想在_Layout.html中渲染它

    ' Show Count of projects
    Function Menu() As PartialViewResult
        Dim count = 15
        Return PartialView(count)
    End Function

Now ive tried using @html.renderpartial("Menu", "Projects") but this did nothing ive also tried things like returning it as a actionresult and using html.renderaction or html.action but both didnt work

现在我尝试使用@html.renderpartial(“菜单”,“项目”),但这没有做任何事情我也尝试过将其作为actionresult返回并使用html.renderaction或html.action但两者都没有工作

Please help me out

请帮帮我

1 个解决方案

#1


0  

You are correct to use ActionResult as the return type of the method.

使用ActionResult作为方法的返回类型是正确的。

When using Html.RenderAction you need to do it like this:

使用Html.RenderAction时,您需要这样做:

@{ Html.RenderAction("About"); }

@ {Html.RenderAction(“关于”); }

If I recall, you need to wrap the call around @{} becasue RenderAction writes it output to the Http response stream, not as a return value of the function. That means calling this:

如果我记得,你需要绕过@ {}来调用它,因为RenderAction将它输出写入Http响应流,而不是函数的返回值。这意味着这称为:

@Html.RenderAction("About")

Will result is nothing being outputted onto the page.

结果是没有输出到页面上。

#1


0  

You are correct to use ActionResult as the return type of the method.

使用ActionResult作为方法的返回类型是正确的。

When using Html.RenderAction you need to do it like this:

使用Html.RenderAction时,您需要这样做:

@{ Html.RenderAction("About"); }

@ {Html.RenderAction(“关于”); }

If I recall, you need to wrap the call around @{} becasue RenderAction writes it output to the Http response stream, not as a return value of the function. That means calling this:

如果我记得,你需要绕过@ {}来调用它,因为RenderAction将它输出写入Http响应流,而不是函数的返回值。这意味着这称为:

@Html.RenderAction("About")

Will result is nothing being outputted onto the page.

结果是没有输出到页面上。