'ASP.Net MVC How to pass url parameters using Html.RenderAction to a ChildAction
I thought this was going to be straight forward but I managed to hose it up some how. If I want to pass URL parameters to another action do I have to create a new route for that?
controller
[ChildActionOnly]
public ActionResult ContentSection(string sectionAlias, string mvcController, string mvcAction = null)
view
@Html.RenderAction("ContentSection", "Portal", new {sectionAlias = "TermsAndConditions", mvcController = "Portal", mvcAction = "ChoosePayment"})
error
CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments
Solution 1:[1]
The short answer is to use @Html.Action() like this:
@Html.Action("ContentSection", "Portal", new {sectionAlias = "Terms", ...})
The long answer was already given by Nathan Anderson.
P.S. Credit for this answer really goes to James Nail, who posted it as a comment in Nathan's answer, but I found it so easy and valuable that I thought it should be an individual answer.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
