加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 18:43:14 所属栏目:asp.Net 来源:网络整理
导读:我以为这是直截了当的,但我设法弄清楚一些如何。如果我想将URL参数传递给另一个操作,那么我必须为此创建一个新的路由? 控制器 [ChildActionOnly] public ActionResult ContentSection(string sectionAlias,string mvcController,string mvcAction = null)
我以为这是直截了当的,但我设法弄清楚一些如何。如果我想将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"}); %>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读