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

谁说我不能喝 提交于 2019-12-12 01:58:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!