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

前端之家收集整理的这篇文章主要介绍了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"}); %>
原文链接:/aspnet/253719.html

猜你在找的asp.Net相关文章