Comments (9)
I see inconsistence: you're using [MvcStyleBinding]
or [MvcActionBinding]
or both ?
from webapicontrib.
in the IHttpActionResult ? i'm use [MvcStyleBinding]
from webapicontrib.
But the error occurs in private class MvcActionBinding
?
from webapicontrib.
Yes, the complete class is:
public class MvcActionValueBinder : DefaultActionValueBinder
{
// Per-request storage, uses the Request.Properties bag. We need a unique key into the bag.
private const string Key = "{5DC187FB-BFA0-462A-AB93-9E8036871EC8}";
public override HttpActionBinding GetBinding(HttpActionDescriptor actionDescriptor)
{
var actionBinding = new MvcActionBinding();
HttpParameterDescriptor[] parameters = actionDescriptor.GetParameters().ToArray();
HttpParameterBinding[] binders = Array.ConvertAll(parameters, DetermineBinding);
actionBinding.ParameterBindings = binders;
return actionBinding;
}
private HttpParameterBinding DetermineBinding(HttpParameterDescriptor parameter)
{
HttpConfiguration config = parameter.Configuration;
var attr = new ModelBinderAttribute(); // use default settings
ModelBinderProvider provider = attr.GetModelBinderProvider(config);
IModelBinder binder = provider.GetBinder(config, parameter.ParameterType);
// Alternatively, we could put this ValueProviderFactory in the global config.
var vpfs = new List<ValueProviderFactory>(attr.GetValueProviderFactories(config)) { new BodyValueProviderFactory() };
return new ModelBinderParameterBinding(parameter, binder, vpfs);
}
// Derive from ActionBinding so that we have a chance to read the body once and then share that with all the parameters.
private class MvcActionBinding : HttpActionBinding
{
// Read the body upfront , add as a ValueProvider
public override Task ExecuteBindingAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
{
HttpRequestMessage request = actionContext.ControllerContext.Request;
HttpContent content = request.Content;
if (content != null)
{
FormDataCollection fd = content.ReadAsAsync<FormDataCollection>().Result;
if (fd != null)
{
IValueProvider vp = new NameValuePairsValueProvider(fd, CultureInfo.InvariantCulture);
request.Properties.Add(Key, vp);
}
}
return base.ExecuteBindingAsync(actionContext, cancellationToken);
}
}
// Get a value provider over the body. This can be shared by all parameters.
// This gets the values computed in MvcActionBinding.
private class BodyValueProviderFactory : ValueProviderFactory
{
public override IValueProvider GetValueProvider(HttpActionContext actionContext)
{
object vp;
actionContext.Request.Properties.TryGetValue(Key, out vp);
return (IValueProvider)vp; // can be null
}
}
}
from webapicontrib.
hello, i'm chage
FormDataCollection fd = content.ReadAsAsync<FormDataCollection>().Result;
for
var fd = content.ReadAsAsync<IDictionary<string, object>>().Result;
and it work but doesn't when send array :(
from webapicontrib.
btw don't use Result
, use async/await
instead
from webapicontrib.
when? in the content.ReadAsAsync<IDictionary<string, object>>().Result?
from webapicontrib.
It's unrelated to the problem you're facing but yes, there and elsewhere, calling the Result property blocks current thread so you're not having async operation spite it looks like you will. If shortly, this is incorrect way to use it.
from webapicontrib.
Regarding your problem, i frankly don't know, I'm not familiar with this part of the codebase. Please ask a question on Stack Overflow and provide a link to the question here, I'll assist if you're facing any issues there
from webapicontrib.
Related Issues (20)
- Incorrect link to JavaScriptSerializer in readme.md HOT 1
- ShouldMapTo url parameters not being recognized HOT 2
- ApiController cannot extend another class HOT 2
- Date time parse error
- UnderscoreMappingResolver HOT 2
- LoggingHandler questions HOT 1
- CommonServiceLocator Nuget Dependency Is Not Needed HOT 1
- Remove TaskHelpers.Sources from App_Packages? HOT 4
- IHttpActionResult HOT 4
- WebApiContrib for ASP.NET MVC 6 HOT 12
- Use table layout in README to show build status and nuget links for all packages HOT 1
- ElmahAggregateExceptionLogger HOT 1
- Push latest to NuGet HOT 16
- Drop the dependency on TaskHelpers.Sources HOT 2
- How to register routes for Testing WebApi routes (WebApiContrib.Testing)?
- MVC Style Bindings - Multiple actions were found ERROR
- Can't get the MvcActionValueBinder to work with json body? HOT 9
- .NET core support HOT 1
- Nested Entities in Web API - System.NotSupported Exception (response.content.legth)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webapicontrib.