C # Automatic Property Deserialization - Lists

I am trying to use automatic deserialization in my MVC action, for example:

public void CreateEntitlementEntity(EntitlementEntityModel model) {
     // stuff
}

And here is the class I want to deserialize:

public class EntitlementEntityModel {
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }

    public List<string> Domains { get; set; }

    public EntitlementEntityModel() { }
}

I pass the JSON data object to the controller action:

data: {
    FirstName: 'first',
    LastName: 'last',
    Email: 'email@email.com',
    Domains: ['a','b','c']
}

All properties are deserialized correctly, except for the list of strings. I would like to turn a JSON array into a list, but instead it gives me a list with one line in it, a JSON array string.

Is there a way to accomplish this in the .NET Framework 3.5?

thank

+3
source share
2 answers

Maybe you can use some input from this stream?

json array deserialization to .net class

+1
source

JsonValueProviderFactory OnApplicationStarted() global.asax, json- .

protected override void OnApplicationStarted()
{
    base.OnApplicationStarted();

    // for managing complex json objects
    ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());
+1

All Articles