Try our conversational search powered by Generative AI!

Redirect to another action method on same page/controller throwing error: No route matches the supplied values

ZZ
ZZ
Vote:
 

We are in process of upgrading EpiServer 11 to Optimizely ver. 12. In this process we have enountered this isse that when redirection from one action method to another the route can't be found and the exception is thrown.

[HttpPost]
        public async Task<IActionResult> PersonalInformation(ZZPage currentPage, XXViewModel model)
        {
            // Validate
            if (!ModelState.IsValid)
            {
                return View("xx", model);
            }

           // regId is equal to some Guid.
            var regId = Guid

            return RedirectToAction("PersonalInformation",
                new
                {
                    id = regId,
                }
            );
        }
-------------------------------------------------------------------------------------------------------------
// This method is on same controller
[HttpGet]
        public async Task<IActionResult> PersonalInformation(ZZPage currentPage, Guid? id = null)
        {

     }

The "RedirectToAction" method is throwing an error 

An unhandled exception occurred while processing the request.

InvalidOperationException: No route matches the supplied values.

Microsoft.AspNetCore.Mvc.Infrastructure.RedirectToActionResultExecutor.ExecuteAsync(ActionContext context, RedirectToActionResult result)

I have also tried to change the name of "PersonalInformation" action method to something different but still got the same error. I even tried to send currentPage as route values but it didn't work

#292795
Edited, Dec 07, 2022 13:13
ZZ
Vote:
 

I have found out that RedirectToContent works but I also need to send paramter(s) and it doesn't have any overload that takes route values -> 

return RedirectToContent(currentPage.PageLink, "PersonalInformation");
#292857
Dec 08, 2022 12:45
ZZ
Vote:
 

Ok. I found out that Redirect method which only takes URL as paramter is working

e.g. ->             

return Redirect($"{currentPage.ContentLink.GetFriendlyUrl()}PersonalInformation/?indmeldelseId={regId}");

but this a primitive way of doing and it also requires manally building URL with all the paramters. Does anyone know why is it not possible to use RedirectToAction()

like this ->

 return RedirectToAction("PersonalInformation",
                new
                {
                    id = registrationUpdated.Id,
                });
#292908
Dec 09, 2022 10:15
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.