Redirect ActionResult

1

Good to all. I'm trying to redirect from one Actionresult to another and have tried everything ever without success. At this point I find 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 error

Child actions are not allowed to perform redirect actions.

Can anyone help?

    
asked by anonymous 18.07.2018 / 12:06

1 answer

2

This happens because the attribute ChildActionOnly is causing this Action Menu can not be accessed except through a View daughter and blocking the redirects (as the error message itself says), this either say that your Action can only return content, not redirects.

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

    
18.07.2018 / 13:38