0

I am using RedirectToAction method and i want to pass two route parameters but its not redirecting to specified action method.

I am using following code:

return RedirectToAction("abcd", "Registration", new { id = "", loginType = "pqr" });

and the specified action method signature is as :

public ActionResult abcd(string id, string loginType = null)

Is there any mistake in signature??

Thanks...

Ufuk Hacıoğulları
  • 37,978
  • 12
  • 114
  • 156
swarraj
  • 25
  • 2
  • 9

1 Answers1

0

Make sure that the abcd() action method is in a class called RegistrationController. If your abcd() action method is in the RegistrationController class then you want to call like this:

return RedirectToAction("abcd", new { id = "", loginType = "pqr" });
iCode
  • 1,254
  • 1
  • 13
  • 16
  • You could also use Fiddler2, Firebug, or press F12 in the browser and view the Network tab to capture the traffic. – iCode May 14 '14 at 12:29
  • One other thing to check; if your return RedirectToAction() call is inside of the RegistrationController class then you want to use the overload for RedirectToAction() that specifies the action method name and the route values (ie. parameters): http://msdn.microsoft.com/en-us/library/dd460291(v=vs.118).aspx – iCode May 14 '14 at 12:35
  • yes,the method is in RegistrationController ,but is there any parameter specific error i.e. parameter naming, actually i am getting "Sequence contains no elements" exception – swarraj May 14 '14 at 12:37
  • Put a breakpoint on your controller action **abcd** and check is it really not calling. – Jitendra Pancholi May 14 '14 at 12:43
  • can u please send the code snippet for how to use RedirectToAction method with multiple route parameters i.e RedirectToAction("","",new {param1 = "Hiii", param2 = "Hiiiii"}) and what should be the specified action method signature to which we are redirecting?? – swarraj May 14 '14 at 12:47
  • Sequence contains no elements indicates most likely that you are trying to get a value out of a collection or list that does not exist. Is abcd() a HttpGet method? – iCode May 14 '14 at 13:21
  • You might want to check your Registration View to see if you are trying to perform an action on your model class that would cause the sequence contains no elements error. Here's another stackoverflow post on that error message: http://stackoverflow.com/questions/1324199/sequence-contains-no-elements – iCode May 14 '14 at 13:40
  • the abcd() method is not decorated with HttpGet attribute,is it necessary?? – swarraj May 14 '14 at 13:47
  • No you do not. ASP.NET MVC defaults to the HTTP GET verb when not specified. – iCode May 14 '14 at 13:50
  • the call is from one controller to another controller thats why i need to specify controller name in the RedirectToAction method – swarraj May 14 '14 at 13:59
  • Just to be clear, when are you seeing the error message? Can you put a breakpoint on the first curly brace for the abcd() method and get there or does the error happen before that point? – iCode May 14 '14 at 14:03
  • Oh, I thought that you said they were both in the RegistrationController class. Yes, then you would want to specify the controller name. The error is not the way that you are calling the RedirectToAction method. The error is most likely caused in your Registration model or viewmodel class. It could be one of the Registration Views (Index, Details, etc.) that has code that is causing the error. – iCode May 14 '14 at 14:06
  • Actually it is executing following line : return RedirectToAction("","",new { }) then it is going to end of the method and then it is going to Disassembly and giving exception "Sequence contains no elements" – swarraj May 14 '14 at 14:23