Passing an object as parameter to Breeze controller action
asp.net-web-api, breeze
Solution
You may be missing a [FromUri] attribute. Any time I tried to pass a more complex object or set of parameters everything would come back as null until I added that attribute.
[BreezeController]
public class AccountController : ApiController
{
[HttpGet]
public LoginResult Authenticate([FromUri] LoginRequest loginRequest)
{
// Object for loginRequest always null
}
}
Problem
I'm trying to send an object as a parameter through Breeze without success. Using the following code I can send a primitive type: Client: ``` var query = EntityQuery .from('account/authenticate') .withParameters({ loginRequest: "hello" }); ``` Server: ``` [BreezeController] public class AccountController : ApiController { [HttpGet] public LoginResult Authenticate(string loginRequest) { // String for loginRequest received successfully } } ``` However, if I try and pass a complex type up, the param is always null: Client: ``` var loginRequest = { userName: 'me', password: 'pass' }; var query = EntityQuery .from('account/authenticate') .withParameters({ loginRequest: loginRequest }); ``` Server: ``` [BreezeController] public class AccountController : ApiController { [HttpGet] public LoginResult Authenticate(LoginRequest loginRequest) { // Object for loginRequest always null } } ``` I believe this is in part because Breeze always uses a GET for queries. A POST might handle the serialization correctly, but I can't see any way in the Breeze API to force a POST. If I pass up a JSON string representation of the object I can pick it up server-side, but this requires manual deserialization. I realise I could do this outside of Breeze with a standard WebAPI call, but I'm trying to keep all of my server-side calls running through the same pipeline. Is it possible to do this?