Comments (9)
Why are you trying to deserialize UpdateAccountCreditLimitRequest (single item) into FormDataCollection (array)? Why do you need MvcActionBinding here?
from webapicontrib.
Here is my SO post which should explain better.
I need MvcActionBinding here because I'm trying to populate a single incoming request object with a parameter FromUri and the rest FromBody. Web Api 2 doesn't allow you to do this out of the box and after searching, I thought this was the way to go.
from webapicontrib.
To formally match request model with model, try using ICollection<UpdateAccountCreditLimitRequest>
.
But here's what works for me out of the box:
[Route("api/payment")]
public async Task<IHttpActionResult> PostStartPayment(StartPaymentRequest request, bool sync = true)
{
}
which is inboked by url:
POST http://example.com/api/payment/?sync=false
{
"foo" : "bar" // request body goes here
}
In other words: try swap arguments order.
P.S.
You don't need [FromBody]
since PUT is from body by default (by the HTTP spec).
P.P.S.
You don't need [HttpPut]
if you name your method PutUpdateAccountCreditLimit()
.
from webapicontrib.
Changing the order of parameters doesn't help. Please see the stack overflow post. Following your example above, if there was a property called sync on your StartPaymentRequest object, it will NEVER be populated FromUrl. How can I get some of the request object's properties to populate via a combination of the body/url? Again I'm using Web Api (not MVC where this works out of the box).
This assumes the body is FormUrl encoded, however, my body is json.
from webapicontrib.
I don't think object's properties can be populated from both, only from either.
My example shows that different parameters can be populated differently (one form body, another from url).
from webapicontrib.
There are tests in this project showing that an object can be populated from both body and uri. Here is the controller in MvcActionValueBinderTests.cs
[MvcStyleBinding]
public class MvcController : ApiController
{
[HttpGet]
public Customer Combined(Customer item)
{
return item;
}
}
Here is the test.
[Test]
public void TestOneFieldFromUriOneFromBody()
{
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("http://localhost:8080/Mvc/Combined?age=10"),
Content = FormUrlContent("name=Fred")
};
var response = client.SendAsync(request).Result;
var actual = response.Content.ReadAsAsync<Customer>().Result;
var expected = new Customer { name = "Fred", age = 10 };
Assert.That(actual, Is.EqualTo(expected));
}
This works. However, there is one difference from this test and what I'm trying to do. I'd like to populate the object from ROUTE data and BODY data (not QUERYSTRING and BODY).
from webapicontrib.
I don't quite get what do you mean "from route". Does it work for you If do this in query string?
from webapicontrib.
Hi i have some problem in angular, in my client
this.prueba = function (id, nombre) {
return $http.post(ApiURL + "AEmpleado/prueba", { id: id, nombre: nombre })
.then(
function (respuesta) {
MensajeServices.MostarMensaje("", "Se elimino el Registro Correctamente", "success", null);
//vm.CargarTabla();
return respuesta
},
function (respuesta) {
console.log(respuesta.data.Message);
return false;
}
);
}
in my server
[RoutePrefix("api/AEmpleado")]
[MvcStyleBinding]
public class AEmpleadoController : ApiController
{
[HttpPost, Route("prueba")]
public IHttpActionResult prueba(int id, string nombre)
{
return Ok();
}
}
anybody help?
Sorry for my english
from webapicontrib.
@allnnde please open a new issue. also explain the problem or error you're facing
from webapicontrib.
Related Issues (20)
- 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
- .NET core support HOT 1
- MvcActionValueBinder Execption in post HOT 9
- Nested Entities in Web API - System.NotSupported Exception (response.content.legth)
- Code search results
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.