web api使用JObject接收时,报“无法创建抽象类”错误

https://bbs.csdn.net/topics/391952288

在下列函数中增加  ModelBinders.Binders.Add(typeof(JObject), new JObjectModelBinder());

public static void RegisterRoutes(RouteCollection routes)
{
ModelBinders.Binders.Add(typeof(JObject), new JObjectModelBinder());
} public class JObjectModelBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var stream = controllerContext.RequestContext.HttpContext.Request.InputStream;
stream.Seek(, SeekOrigin.Begin);
string json = new StreamReader(stream).ReadToEnd();
return JsonConvert.DeserializeObject<dynamic>(json);
}
}
上一篇:Form Personalization应用总结


下一篇:MySQL高可用主从复制新增slave