Returning a PartialView from an ActionResult, downside?

I have an ActionResult setup that returns a PartialView under normal circumstances but if there is an error it does a RedirectToACtion to my error page. Testing the page out real quick makes things look like it is working fine. Is there a downside to what
I am doing?

        [ChildActionOnly]
        public ActionResult SectionNavigation()
        {
            try
            {
                using (SectionContext db = new SectionContext())
                {
                    string SectionRoute = (string)RouteData.Values["SectionRoute"];

                    var model = db.NavigationLinks
                                  .Where(nl => nl.Section.Route == SectionRoute)
                                  .Select(nl => new NavigationLinksVM
                                  {
                                      LinkType = nl.Type,
                                      SectionType = (nl.Section.Type != "Cinema") ? nl.Section.Type + "s" : nl.Section.Type,
                                      Route = nl.Section.Route,
                                      URL = nl.URL,
                                      Title = nl.Title
                                  }).ToList();
                    return PartialView("Layout/SectionNavigation", model);
                }
            }
            catch (Exception ex)
            {
                ErrorSignal.FromCurrentContext().Raise(ex);
                return RedirectToAction("Error500", "Home");
            }
       

other than you can not redirect from a child action, it throws an error, so there is no point in the redirect. just throw an error.

personally I think using child actions is a poor design choice anyway.

If you really want your users to see an error message you can always return the error view as a partial view instead of returning the default view

return PartialView("Views/Home/Error500");

This will only work if the view doesn’t take any data from the controller.

bruce (sqlwork.com)

other than you can not redirect from a child action, it throws an error, so there is no point in the redirect. just throw an error.

personally I think using child actions is a poor design choice anyway.

I am still new to .Net so I would love to hear your  opinion on why Child Actions are poor design. I would also presume that if I simply removed the ChildActionOnly tag that the redirect would work.

Leave a Reply