问题
I figured it'd be easier to ask here, where I can post some code, than in the comments of his solution. To see his solution, go here.
EDIT: Some progress, but a new error. In my ErrorController class, I'm getting a NotImplementedException:
public ActionResult InvokeHttp404(HttpContextBase httpContext)
{
IKernel kernal = new StandardKernel();
IController errorController = kernal.Get<ErrorController>();
var errorRoute = new RouteData();
errorRoute.Values.Add("controller", "Error");
errorRoute.Values.Add("action", "Http404");
errorRoute.Values.Add("path", httpContext.Request.Url.OriginalString);
errorController.Execute(new RequestContext(
httpContext, errorRoute)); // <-- here
return new EmptyResult();
}
Specifically, the exception message is:
The model item passed into the dictionary is of type 'HandiGamer.WebUI.Controllers.NotFoundViewModel', but this dictionary requires a model item of type 'System.String'.
I'm not sure which dictionary it's referring to, and MSDN has been less than helpful.
回答1:
Oh God, the problem was me being an idiot. I neglected to change my view, so it was still anticipating a simple string
for its view model rather than a NotFoundViewModel
. Since IController.Execute()
was being called in the raw, it was throwing an exception due to the view's internal dictionary not being set to accept the view model.
@cottsak, thanks for all your help and patience.
来源:https://stackoverflow.com/questions/5808554/asp-net-mvc-2-route-errors-problems-when-using-cottsaks-solution