我以为这是直截了当的,但我设法弄清楚一些如何。如果我想将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"}); %>