gpt4 book ai didi

asp.net-mvc - ASP.Net MVC 如何使用 Html.RenderAction 将 url 参数传递给 ChildAction

转载 作者:行者123 更新时间:2023-12-02 16:09:03 25 4
gpt4 key购买 nike

我以为这会很简单,但我设法以某种方式将其解决。如果我想将 URL 参数传递给另一个操作,我是否必须为此创建一个新路由?

Controller

[ChildActionOnly]
public ActionResult ContentSection(string sectionAlias, string mvcController, string mvcAction = null)

查看

@Html.RenderAction("ContentSection", "Portal", new {sectionAlias = "TermsAndConditions", mvcController = "Portal", mvcAction = "ChoosePayment"})

错误

 CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments

最佳答案

这里的问题是

@Html.RenderAction("ContentSection", "Portal", new {sectionAlias = "TermsAndConditions", mvcController = "Portal", mvcAction = "ChoosePayment"})

相当于

<%= Html.RenderAction("ContentSection", "Portal", new {sectionAlias = "TermsAndConditions", mvcController = "Portal", mvcAction = "ChoosePayment"}) %>

在Webforms ViewEngine 中(这也是同一个Response.Write)。由于 RenderAction 返回 void,因此您无法 Response.Write 它。你想做的是这样的:

@{
Html.RenderAction("ContentSection", "Portal", new {sectionAlias = "TermsAndConditions", mvcController = "Portal", mvcAction = "ChoosePayment"});
}

@{ } 语法表示 Razor View 引擎中的代码块,相当于以下 Webforms ViewEngine:

<% Html.RenderAction("ContentSection", "Portal", new {sectionAlias = "TermsAndConditions", mvcController = "Portal", mvcAction = "ChoosePayment"}); %>

关于asp.net-mvc - ASP.Net MVC 如何使用 Html.RenderAction 将 url 参数传递给 ChildAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4964042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com