0

Please help me, in my controller I am having 2 action methods with same name called "Index" but with different parameters ..

 public ActionResult Index()
        {...}

 [HttpPost] 

 public ActionResult Index(PickingMobile mi, string hdnSelectOperation, string btnMPSearch, string btnSearchMP)
        {...}

Now from other action I want to redirect to Index action which has no parameters

public ActionResult ConfirmBatchPicking(PickingMobile DirectPicking)
        {
...
 return RedirectToAction("Index", "ManualPickingSearch");// from here I need to redirect to first Index Method which does not have any parameters
          }

But when I keep the break point and debugging the sequence, the first Index method is not getting hit. Please help me , how to redirect to first Index action.

Madhavan NR
  • 178
  • 1
  • 1
  • 13
  • As your one of the Index method is HttpPost type, So When you call return RedirectToAction("Index", "ControllerName"). This will redirect you to HttpGet method – 111 Jul 10 '14 at 04:33
  • But is not hitting the first Index method while debufgging – Madhavan NR Jul 10 '14 at 04:35

2 Answers2

1
  1. RedirectToAction returns RedirectToRouteResult to browser in response. This response makes browser to make a new get request to another action method(in your case Index action in ManualPickingSearchcontroller)
  2. Your second Index action (one with parameter) is attached with httpPost attribute.It means only post request can be made to it.

And so, when you say return RedirectToAction("Index", "ManualPickingSearch"); it will redirect to first action method by default. Its the default behavior. Its how it should work. Please check if you are missing something.(Check the controller Name)

Sukesh Marla
  • 178
  • 11
0

Try this;

return RedirectToAction("Index");
Saranga
  • 3,178
  • 1
  • 18
  • 26
  • OK, if you use `RedirectToAction("Index", "ManualPickingSearch");` it will redirect to `ManualPickingSearch` controller's `Index` method. Thanks! – Saranga Jul 10 '14 at 04:29
  • Ya I want to redirect to the Index method in ManualPIckingSearch only. But the problem is I have 2 index mehtods – Madhavan NR Jul 10 '14 at 04:31
  • You don't need to put controller name if you want to call a method in same controller. As long as you don't put `[HttpPost]` in your first `Index`method, there will be no issues. – Saranga Jul 10 '14 at 04:47
  • Are there any `Index` methods (Not `[HttpPost]` one) with different parameters ? – Saranga Jul 10 '14 at 05:01
  • Ya I have one with no parameters – Madhavan NR Jul 10 '14 at 06:37