开发者

ASP.NET MVC 2 route errors - problems when using cottsak's solution

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 M开发者_如何学运维SDN has been less than helpful.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜