异常详细信息: System.MissingMethodException: 无法创建抽象类。

 

asp.net mvc

在使用post向后端传送json数据时报异常,在路由配置中添加如下即可

        public static void RegisterRoutes(RouteCollection routes)
        {
            ModelBinders.Binders.Add(typeof(JObject), new JObjectModelBinder());
            //routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapMvcAttributeRoutes();//使用自定义路由
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Login", action = "Index", id = UrlParameter.Optional }
            );
        }

        public class JObjectModelBinder : IModelBinder
        {
            public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
            {
                var stream = controllerContext.RequestContext.HttpContext.Request.InputStream;
                stream.Seek(0, SeekOrigin.Begin);
                string json = new StreamReader(stream).ReadToEnd();
                return JsonConvert.DeserializeObject<dynamic>(json);
            }
        }

 

上一篇:php – Laravel 5路由未定义,而它是?


下一篇:flutter routes跳转