Mvc: Best way to call a controller action method programatically and return IActionResult

Created on 26 Aug 2016  路  4Comments  路  Source: aspnet/Mvc

I'm following up with issue opened on home repository: https://github.com/aspnet/Home/issues/1543
I guess that was a wrong place to ask the question.

How to call a controller action method in C# and get IActionResult back from the executed controller?

question

All 4 comments

Is your question still about use of methods in Internal namespaces, specifically whether using ControllerActionExecutor is the right thing to do for your CMS scenario?

If yes, the answer is "it depends". Classes in Internal namespaces are subject to change and not intended for primary scenarios. But of course, your scenario may need ControllerActionExecutor and you might be fine with future breaking changes.

@sebastienros may have some ideas on alternate approaches for your scenario. Or you could start with Orchard 2 instead of "just" MVC.

One thought: Would creating an alternate IViewComponentInvoker which delegates to DefaultViewComponentInvoker and does extra stuff in InvokeAsync() work for you?

Thanks @dougbu for replying.

I have tried ViewComponents, however, it doesn't support other verbs such as POST, PUT and DELETE. I guess ViewComponents are ideal for rendering trivial components such as navigation and language switcher.

Area is appropriate to build modular components such as Login/Registration, because it supports all verbs and return IActionResults. These components could be rendered anywhere in the website.

In future, it would be highly appreciated when the method "ControllerActionExecutor.Execute()" is available for primary scenarios.

My apologies for the confusing mention of view components; they are not controllers. I was looking at the wrong use of ControllerActionExecutor and should have mentioned IActionInvoker and ControllerActionInvoker. But that wouldn't have been useful since even the ControllerActionInvokerProvider is in an Internal namespace. Just ignore that last paragraph...

We are closing this issue because no further action is planned for this issue. If you still have any issues or questions, please log a new issue with any additional details that you have.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DamianEdwards picture DamianEdwards  路  3Comments

saf-itpro picture saf-itpro  路  3Comments

workmonitored picture workmonitored  路  3Comments

miroslavsiska picture miroslavsiska  路  4Comments

bugproof picture bugproof  路  3Comments