That's not how you do error handling in MVC. In MVC you should register a global exception filter as documented here for ASP.NET. This will likely solve the problem you're having.
You didn't really explain what problem you're actually having. The path looks reasonable other than the fact that your String.FOrmat
call is using an ordinal of 1 but you have only 1 actual argument. Provided your ErrorController
class has an action called Index
and inside that action you eventually call return View("Error")
then it'll render properly.
String.Format("~/error/index?message={0}", HttpUtility.UrlEncode(exception.Message));
Note that MVC provides the Url
property on a controller (which is backed by a type) to give you back the URL to an action without you having to manually encode it. I'm just not sure it can be used this low level. The property isn't available because you aren't in a controller but the underlying type could still work. Never tried it since this is non-standard error handling anyway.
Besides a global exception filter I'll also point out that the default ASP.NET template already provides an error page for you and is configured to be used. Having an error controller is overkill. In general you have a single Error.cshtml
view that you can customize, no controller to back it and let the framework do its thing.