Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC 3 get ActionResult of an action that is defined on a different controller
    primarykey
    data
    text
    <p><strong>Problem:</strong></p> <p>What I need is something similar to @Html.RenderAction("action","controller") , but one that I can use from inside a different controller. This for example:</p> <pre><code>public class FirstController : Controller { public ActionResult GetErDone() { return View(); } } public class SecondController : Controller { public ActionResult Index() { ActionResult coolResult = Helper.GetActionResult("GetErDone", "FirstController"); return View(); } } </code></pre> <p><strong>Progress:</strong></p> <p>I have begun to strip/reform the actual @Html.Action() method but it really has too many internal helper dependencies and I am thinking this shouldn't be that tough. What I have so far is:</p> <pre><code> private void TestCreateActionFromDifferentController(RouteValueDictionary routeValues, string controllerName, string actionName) { var httpContext = this.HttpContext; var routeData = this.RouteData; routeData.Values["action"] = (object)actionName; if (!string.IsNullOrEmpty(controllerName)) routeData.Values["controller"] = (object)controllerName; IController myController = ControllerBuilder.Current.GetControllerFactory().CreateController(new RequestContext(httpContext, routeData) , "staticpages"); } </code></pre> <p>This works partially of course (minus the many shortcomings like area data tokens etc) but still there is no way other than reflection to get to the <code>MyActionResult</code> object.</p> <p><strong>Summary:</strong></p> <p>When inside a controller, what is a way to get an ActionResult from an action that is defined on a different controller, ?</p> <p><strong>Update:</strong></p> <p>More specifically, I am trying to use something like System.Web.Mvc.Html.ChildActionExtensions.ChildActionMvcHandler but one that doesnt execute, rather it returns the ActionResult</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload