ASP.NET MVC 2路由错误-使用cottsak解决方案时出现问题 [英] ASP.NET MVC 2 route errors - problems when using cottsak's solution

查看:69
本文介绍了ASP.NET MVC 2路由错误-使用cottsak解决方案时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为在这里问,在哪里可以发布一些代码比在他的解决方案的注释中要容易得多.要查看他的解决方案,请在此处.

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.

有些进步,但是有新的错误.在我的ErrorController类中,我收到一个NotImplementedException:

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:

传递到字典中的模型项的类型为'HandiGamer.WebUI.Controllers.NotFoundViewModel',但是此字典需要类型为'System.String'的模型项.

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'.

我不确定它指的是哪本词典,而MSDN的帮助不足.

I'm not sure which dictionary it's referring to, and MSDN has been less than helpful.

推荐答案

哦,天哪,我是个白痴.我忽略了更改视图的想法,因此它仍然期望其视图模型使用简单的string而不是NotFoundViewModel.由于IController.Execute()是在原始文件中调用的,由于未将视图的内部字典设置为接受视图模型,因此它抛出了异常.

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,感谢您的所有帮助和耐心.

@cottsak, thanks for all your help and patience.

这篇关于ASP.NET MVC 2路由错误-使用cottsak解决方案时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆