Tuesday 18 October 2011

MVC4 Json Response with redirect to another controller

I had a colleague that was having an issue passing parameters out of the default JsonResult JsonLogOn method in the AccountController.cs. This template is created for you when you create a new MVC 4 Internet project. Basically once the user was logged on he wanted to send the user to a new view associated with a different controller and he wanted to do this while retaining all of the parameters he has been collecting along the way.

Below you will see how you can redirect the Json call using the UrlHelper "Url.Action" to specify the Action, Controller and parameters to send to the new location. I hope this saves others frustration and time!