Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class JsonBinderAttribute : CustomModelBinderAttribute
- {
- public override IModelBinder GetBinder()
- {
- return new JsonModelBinder();
- }
- public class JsonModelBinder : IModelBinder
- {
- public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
- {
- try
- {
- if (controllerContext == null)
- throw new ArgumentNullException("controllerContext");
- if (bindingContext == null)
- throw new ArgumentNullException("bindingContext");
- //object obj2 = Activator.CreateInstance(bindingContext.ModelType);
- Type genericType = new System.Web.Script.Serialization.JavaScriptSerializer().GetType();
- Type repositoryType = genericType;
- object repository = Activator.CreateInstance(repositoryType);
- System.Reflection.MethodInfo genericMethod = repositoryType.GetMethod("Deserialize");
- System.Reflection.MethodInfo closedMethod = genericMethod.MakeGenericMethod(bindingContext.ModelType);
- return closedMethod.Invoke(repository, new[] { HttpContext.Current.Request[bindingContext.ModelName] });
- }
- catch
- {
- return null;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement