首页 新闻 赞助 找找看

项目中遇到的问题 MVC

0
悬赏园豆:5 [待解决问题]

错误:The model item passed into the dictionary is of type 'FN.Web.Models.ErrorDisplay', but this dictionary requires a model item of type 'System.Web.Mvc.HandleErrorInfo'.

这是Global.asax .cs

namespace FN.Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode,
    // visit http://go.microsoft.com/?LinkId=9394801
    public class MvcApplication : HttpApplication
    {
        public static string ConnectionName = "ApplicationServices";
        public static Settings GlobalSettings = Settings.Instance();
        public static bool ServiceIsStrating;
        /// <summary>
        /// Registers the global filters.
        /// </summary>
        /// <param name="filters">The filters.</param>
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
            Log.WriteEssentialLog("注册全局过滤器", "Initialization");
        }

        /// <summary>
        /// Handles the BeginRequest event of the Application control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            if (!ServiceIsStrating)
            {
                HttpContext.Current.Response.Write("服务尚未初始化。");
                HttpContext.Current.Response.End();
                HttpContext.Current.Response.Clear();
            }
        }

        /// <summary>
        /// Registers the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        public static void RegisterRoutes(RouteCollection routes)
        {
            //设置忽略路由映射
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            //初始化路由映射
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new {controller = "Home", action = "Index", id = UrlParameter.Optional}, // Parameter defaults
                new[] {"FN.Web.Controllers"}
                );
            Log.WriteEssentialLog("初始化路由映射", "Initialization");
        }

        protected void Application_Error(object sender, EventArgs e)
        {
            var exception = Server.GetLastError();
            // Log the exception.
            Log.WriteExceptionLog(exception, "Exceptions");
            Response.Clear();

            var httpException = exception as HttpException;

            var routeData = new RouteData();
            routeData.Values.Add("controller", "Error");

            if (httpException == null)
            {
                routeData.Values.Add("action", "Index");
            }
            else //It's an Http Exception, Let's handle it.
            {
                switch (httpException.GetHttpCode())
                {
                    case 404:
                        // Page not found.
                        routeData.Values.Add("action", "HttpError404");
                        break;
                    case 505:
                        // Server error.
                        routeData.Values.Add("action", "HttpError505");
                        break;

                    // Here you can handle Views to other error codes.
                    // I choose a General error template 
                    default:
                        routeData.Values.Add("action", "Index");
                        break;
                }
            }

            // Pass exception details to the target error View.
            routeData.Values.Add("error", exception);

            // Clear the error on server.
            Server.ClearError();

            // Call target Controller and pass the routeData.
            IController errorController = new ErrorController();

    在这行总是报上面的错误!!!!!!!!!!!!!
            errorController.Execute(new RequestContext(
                 new HttpContextWrapper(Context), routeData));
        }

        /// <summary>
        /// Application_s the start.
        /// </summary>
        protected void Application_Start()
        {
            Log.WriteEssentialLog("-----系统开始进行初始化", "Initialization");
            Db.NameOrConnectionString = "name=ApplicationServices";
            //初始化数据模型
            Initializer.Set(InitializerOperation.DropCreateDatabaseIfModelChanges);
            Log.WriteEssentialLog("初始化数据模型", "Initialization");

            //注册区域
            AreaRegistration.RegisterAllAreas();
            Log.WriteEssentialLog("注册区域", "Initialization");

            //注册全局筛选器
            RegisterGlobalFilters(GlobalFilters.Filters);
            Log.WriteEssentialLog("注册全局筛选器", "Initialization");

            //注册路由器
            RegisterRoutes(RouteTable.Routes);
            Log.WriteEssentialLog("注册路由器", "Initialization");

            IUnityContainer container = GetUnityContainer();
            DependencyResolver.SetResolver(new UnityDependencyResolver(container));
            Log.WriteEssentialLog("系统初始化完毕-----", "Initialization");
            ServiceIsStrating = true;
        }

        /// <summary>
        /// Gets the unity container.
        /// </summary>
        /// <returns></returns>
        private IUnityContainer GetUnityContainer()
        {
            //Create UnityContainer         
            IUnityContainer container = new UnityContainer();
            container.RegisterType<IControllerActivator, CustomControllerActivator>(); // No nned to a controller activator
            container.RegisterType<IClubPluginService, ClubPluginService>(
                new HttpContextLifetimeManager<IClubPluginService>());
            container.RegisterType<IFilesPluginService, FilesPluginService>(
                new HttpContextLifetimeManager<IFilesPluginService>());
            container.RegisterType<IPostPluginService, PostsPluginService>(
                new HttpContextLifetimeManager<IPostPluginService>());
            container.RegisterType<IUserPluginService, UserPluginService>(
                new HttpContextLifetimeManager<IUserPluginService>());
            return container;
        }
    }

赤脚程序员的主页 赤脚程序员 | 初学一级 | 园豆:195
提问于:2011-09-05 18:30
< >
分享
所有回答(3)
0

这里的代码没有问题,问题应该不是出在这里,你断点调试一下看看

artwl | 园豆:16736 (专家六级) | 2011-09-05 19:33
0

在页面中把这个也引用进去 @model System.Web.Mvc.HandleErrorInfo

慧☆星 | 园豆:5640 (大侠五级) | 2011-09-06 09:10
0

错误:The model item passed into the dictionary is of type 'FN.Web.Models.ErrorDisplay', but this dictionary requires a model item of type 'System.Web.Mvc.HandleErrorInfo'.

我想错误信息已经说的很明白了,你传递给View的Model的类型不正确

上不了岸的鱼 | 园豆:4613 (老鸟四级) | 2011-11-29 19:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册