Redirect Actionresult

Asked

Viewed 198 times

1

Good for everyone. I am trying to redirect from one Actionresult to another and I have tried everything unsuccessfully. At this moment I find myself with the following code:

  [AllowAnonymous]
            public ActionResult Index_GA_ER(string tkn)
            {
                return RedirectToAction("Index", "Eresults_Base");
            }

        [ChildActionOnly]
        public ActionResult Menu()
        {           
            var menuOptions = Session.GetDataFromSession<List<Menu>>(StoreManagerKeys.Menus);
            string tkn = "";
            string a = "Eresults_MenuOption_";

                if (ConfigurationManager.AppSettings["generateInterfeatures"] != "true" || menuOptions != null)
                {
                    foreach (var button in menuOptions)
                    {
                        string b = RemoveDiacritics(button.Description).Replace(" ", "_");

                        button.MenuClass = a + b;
                    }

                    return PartialView(menuOptions);
                }
            return Index_GA_ER(tkn);
        }

For which I have the mistake

Child actions are not allowed to perform redirect actions.

Someone can help out ?

  • Take a look at your actionfilter if you have it [Actionfilters.Requirehttps(Requiresecure = false)] if it does change to true try again. https://stackoverflow.com/questions/25015833/child-actions-are-not-allo-allowed-to-perform-redirect-actions-after-setting-the-sit

  • The error happens in which row, when it returns the partial or in the method "Index_ga_er"?

1 answer

2

This happens because the attribute ChildActionOnly is making this Action Menu cannot be accessed other than through a View daughter and blocking the redirects (as the error message itself says), it means that this your Actioncan only return content, not redirects.

You can remove the attribute (since if you want to redirect, it makes no sense to have it in the method).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.