Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net MVC - post from one controller to another (action to action)

Is is possible to do a post from an Action "Save" in a controller "Product" to an Action "SaveAll" in a controller "Category"??

And also passing a FormCollection as parameter

like image 372
André Miranda Avatar asked Apr 30 '10 16:04

André Miranda


People also ask

How do I move from one action to another in MVC?

To redirect the user to another action method from the controller action method, we can use RedirectToAction method. Above action method will simply redirect the user to Create action method.

How do you call an action from another controller?

I'm assuming you want to return that action's result. var ctrl= new MyController(); ctrl. ControllerContext = ControllerContext; //call action return ctrl. Action();


1 Answers

Put the following code in your Product controller:

return RedirectToAction("SaveAll", "Category")

Here, "SaveAll" is an Action Name and "Category" is Controller Name. The user will then be redirected to the SaveAll action (i.e., the method will be called).

like image 54
Maheshwari Kahar Avatar answered Oct 08 '22 23:10

Maheshwari Kahar