ASP.NET MVC (POST) : my parameters are binded only with a JQuery script but not with Fiddler

StackOverflow https://stackoverflow.com/questions/23296036

Pergunta

I created an ASP.NET MVC 4 controller that looks like this :

[Serializable]
public class apiArgument
{
    public string token { get; set; }
    public int language { get; set; }
    public string emailAddress { get; set; }
}

public class myController : ApiController
{
    [HttpPost]
    public HttpResponseMessage postSomething( [FromBody]apiArgument postedArgument )
    {
        ...
    }       
}

But, when I test my controller with Fiddler 4.4.7.1, the controller and action are found but postedArgument is instantiated with empty values.

User-Agent: Fiddler
Content-type: application/json; charset=utf-8
Host: 1.1.1.1:8081
Content-Length: 60

{ token:"test", language: 1036, emailAddress: "foo@bar.fr" }

I have the same result with AFNetworking 2.0

Strangly, the object is binded correctly when I test my controller with a JQuery script:

<script>
    $(document).ready(function()
    {
        var request = $.ajax(
        {
            type: "POST",
            url: "http://1.1.1.1:8081/myController/postSomething",
            data: { token: 'test', language: 1036, emailAddress: 'foo@bar.fr' },
        });

        request.done(function (data) 
        {
            alert('posted!');
        });

        request.fail(function (jqXHR, textStatus) 
        {
            alert(textStatus);
        });

    });
</script>

So, I think that the configuration of my routes are good.

I don't understand what is the difference ?

Do you know why it does not work with Fiddler and AFNetworking ?

Many thanks for your help.

Foi útil?

Solução

The error comes from the attribute [Serializable]. I removed it and everything works!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top