how can you deserialize a dictionary without having brackets 0 added to the key?

One soulution to my problem is to create a custom model bind, so this is what am using now, but I dont understand why I need to, and I feel like there should be a easyer way? But am gonna leve It here anyhow.

public class FromJsonBodyAttribute : CustomModelBinderAttribute
{
    public override IModelBinder GetBinder()
    {
        return new JsonModelBinder();
    }

    private class JsonModelBinder : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var stream = controllerContext.HttpContext.Request.InputStream;
            stream.Position = 0;
            using (var reader = new StreamReader(stream))
            {
                var checkoutOrderDataStr = reader.ReadToEnd();
                return JsonConvert.DeserializeObject(checkoutOrderDataStr, bindingContext.ModelType);
            }
        }
    }
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top