Alex Zhukovskiy
Alex Zhukovskiy

Reputation: 10015

Why MVC is not binding byte array?

If I remember properly, my application was binding successfully everything. But now it doesn't, and I don't know, it never did or I broke something.

Here is a controller:

    public void SaveToDataBase(EnhancedXml enhancedXml)
    {

    }

where EnhancedXml is very simple:

public class EnhancedXml
{
    public string Content { get; set; }
    public byte[] AdvancedSignature { get; set; }
}

Here is my HttpRequest:

POST http://localhost:35921/SaveToDb HTTP/1.1
Content-Type: application/json
X-Requested-With: XMLHttpRequest
Referer: http://localhost:35921/
Accept-Language: en-US,en;q=0.7,ru;q=0.3
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Length: 38027
Host: localhost:35921
Connection: Keep-Alive
Pragma: no-cache

{"enhancedXml":{"Content":"<?xml version=\"1.0\" encoding=\"utf-8\"?><Student xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Name>Alex</Name><LastName>B</LastName><DateOfBirth>1993-05-18T00:00:00</DateOfBirth></Student>","AdvancedSignature":[60,63,120,109,108,32,118,101,114,115,105,111,110,61,34,49,46,48,34,32,101,110,99]}}

When Content property is binding fine, AdvancedSignature doesn't at all. Can it be fixed in some way except `create a string property and marshall an array on your own"?

Upvotes: 0

Views: 252

Answers (1)

cvraman
cvraman

Reputation: 1697

The datatype for your Advanced Signature is wrong. It should be a list of integers.

public class EnhancedXml
{
    public string Content { get; set; }
    public List<int> AdvancedSignature { get; set; }
}

Upvotes: 1

Related Questions