0

While debugging, I cannot display my Error view when an Exception occurs in my controller.

I know I'm missing something here, but cannot figure it out. It never makes it to my ErrorController.

I have a Controller in the Controllers folder called ErrorController.

I can verify the error message in the model variable when it's created.

Here is the exception code in my Controller:

filterContext.ExceptionHandled = true;
            var model = new HandleErrorInfo(filterContext.Exception, "Error", "Index");

            filterContext.Result = new ViewResult()
            {
                ViewName = "~/Views/Shared/Error",
                ViewData = new ViewDataDictionary<HandleErrorInfo>(model)
            };

My Error controller simply looks like this:

public class ErrorController : Controller
    {
        // GET: ErrorController
        public ViewResult Index()
        {
            return View();
        }
    }

Can someone tell me what I'm overlooking here?

1 Answer 1

1

You should give the view name the extension .cshtml if C#, or .vbhtml if VB.

Reference.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.