Taking action without redirecting

I have a small question for the community. Can ASP.NET MVC perform another controller action without a method RedirectToAction()

and without instantiating that controller?

+1


a source to share


3 answers


It's impossible. To run an instance, there must be an instance to run. Action methods are just methods like all other methods, so you always need an instance to call a method.



+2


a source


You want to have a view that returns nothing. No viewing. No nadda?

If so, u can return EmptyResult class ViewResult ...



NTN.

0


a source


You can call it a technique Reflection

, but it is not recommended . Soon, because it's not in the request / response / controller context.
Personally, I prefer to have internal static method(bla bla){...}

and name it wherever I want.
But if you let go

without instantiating this controller

... Then you can use this methodology . But as explained, It Is Not Recommended Too . summarizes the following:

var controller = new FooController();
controller.ControllerContext = new ControllerContext(this.ControllerContext.RequestContext, controller);
var jsonResult = controller.BlaMethod(someInputParams);

      

0


a source







All Articles