Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Source/MultiPostParameterBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public override Task ExecuteBindingAsync(ModelMetadataProvider metadataProvider,
stringValue = parameters[Descriptor.ParameterName];

// if not found in body, try reading query string
if (stringValue == null)
if (stringValue == null && !parameters.AllKeys.Contains(Descriptor.ParameterName))
{
var queryStringPairs = actionContext.Request.GetQueryNameValuePairs();
if (queryStringPairs != null)
Expand All @@ -84,14 +84,18 @@ public override Task ExecuteBindingAsync(ModelMetadataProvider metadataProvider,
else if (Descriptor.ParameterType.IsEnum)
paramValue = Enum.Parse(Descriptor.ParameterType, stringValue);
else if (Descriptor.ParameterType.IsPrimitive || Descriptor.ParameterType.IsValueType) // TODO: Are these conditions ok? I'd rather not have to check that the type implements IConvertible.
paramValue = Convert.ChangeType(stringValue, Descriptor.ParameterType);
paramValue = TypeDescriptor.GetConverter(Descriptor.ParameterType).ConvertFromInvariantString(stringValue);
else
// when deserializing an object, pass in the global settings so that custom converters, etc. are honored
paramValue = JsonConvert.DeserializeObject(stringValue, Descriptor.ParameterType, GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings);

// Set the binding result here
SetValue(actionContext, paramValue);
}
else if(parameters.AllKeys.Contains(Descriptor.ParameterName))
{
SetValue(actionContext, null);
}

// now, we can return a completed task with no result
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
Expand Down Expand Up @@ -125,7 +129,7 @@ private NameValueCollection ParseParametersFromBody(HttpRequestMessage request)
var values = JsonConvert.DeserializeObject<Dictionary<string, object>>(content);
result = values.Aggregate(new NameValueCollection(), (seed, current) =>
{
seed.Add(current.Key, current.Value == null ? "" : current.Value.ToString());
seed.Add(current.Key, current.Value == null ? null : current.Value.ToString());
return seed;
});
break;
Expand Down Expand Up @@ -171,4 +175,4 @@ public static MultiPostParameterBinding CreateBindingForMarkedParameters(HttpPar
}

}
}
}