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

我以为这是直截了当的,但我设法弄清楚一些如何。如果我想将URL参数传递给另一个操作,那么我必须为此创建一个新的路由?

控制器

[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",mvcAction = "ChoosePayment"})

相当于

<%= Html.RenderAction("ContentSection",mvcAction = "ChoosePayment"}) %>

在Webforms ViewEngine中(这也是Response.Write的一样)。由于RenderAction返回void,您不能Response.Write它。你想做的是这样的:

@{
     Html.RenderAction("ContentSection",mvcAction = "ChoosePayment"});
 }

@ {}语法表示Razor视图引擎中的一个代码块,它将等同于以下Webforms ViewEngine:

<% Html.RenderAction("ContentSection",mvcAction = "ChoosePayment"}); %>

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....