Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8896093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:57:19+00:00 2026-06-14T23:57:19+00:00

I have an Action that returns a PartialView: [ChildActionOnly] public ActionResult TabInfo(int id, string

  • 0

I have an Action that returns a PartialView:

[ChildActionOnly]
public ActionResult TabInfo(int id, string tab)
{

    ViewBag.Jobid = id;
    ViewBag.Tab = tab;

    var viewModel = _viewModelManager.GetViewModel(tab, id);

    return 
        PartialView(string.Format("~/Views/{0}/Index.cshtml", tab), viewModel);

}

The _viewModelManager returns a view from a Dictionary. If a user requests a tab that does not exsist then a KeyNotFound Exception will be thrown, however, In my view I get the following Exception:

Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'

@using MyApplication.UI.Helpers.Html
@model MyApplication.UI.Models.MyJobModel

@{
    ViewBag.Title = "Details";
}

<p>@Model.Blah</p>

...

*@ HttpException occurs here -- renders default error view *@
@Html.Action("TabInfo", new { id = ViewBag.Jobid, tab = ViewBag.Tab }) 

According to MS…

The HandleErrorAttribute attribute on a child action method is ignored if an exception occurs in the child action itself. Therefore, a child action should handle its own exceptions. If a child action has an AuthorizeAttribute attribute applied, the attribute will execute and return an HTTP Unauthorized 401 status code.

I can’t user this [HandleError(ExceptionType = typeof(KeyNotFoundException), View="myError")] and I can’t redirect using a try/catch either because redirects for child actions are not supported.

What is the best way to handle child action exceptions?

Bottomline: I want to handle the exception and return a custom error page.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:57:21+00:00Added an answer on June 14, 2026 at 11:57 pm

    In case anyone else comes across this question.

    I ended up using a try/catch block to catch the KeyNotFound exception. I log the error and then redirect the user to an ErrorView. In the error view I redirect the user to the appropriate view using javascript.

    [ChildActionOnly]
        public ActionResult TabInfo(int id, string tab, string jobno)
        {
            try
            {
                var viewModel = _viewModelManager.GetViewModel(tab, id);
    
                ViewBag.Jobid = id;
                ViewBag.Tab = tab;
    
                return PartialView(string.Format("~/Views/{0}/Index.cshtml", tab), viewModel);
            }
            catch (Exception ex)
            {
                return View("Error");
            }
    
        }
    

    Error View

    @model System.Web.Mvc.HandleErrorInfo
    
    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
    </head>
    <body>
        <script type="text/javascript">
            window.location.href = '@Url.Content("~/400.htm")';
        </script>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following action method that initiated SelectList as follow:- public PartialViewResult Search(string
I have the following action method that returns a collection of AdminDetail instances: public
I have a controller action which renders a partial view: public ActionResult Details(int id)
I have the following controller action: public ActionResult Details(string pk) { IEnumerable<ContentDetail> model =
Suppose I have an action that returns an rendered asp.net mvc control and send
I'm have an action /json that returns json from the server. Unfortunately in IE,
If i have a controller action Create that returns a view with the following
I have an asp.net mvc action that returns a file result. Behind the scenes,
I have parent view that also renders sub-controller action using RenderAction() (that returns a
I have an action that creates a List and returns it to my view..

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.