Question

I have two models in my MVC4 application defined like this:

public class Attendee
{
    public string ID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string DOB { get; set; }
    public string Address1 { get; set; }
    public string Address2 { get; set; }
    public string Address3 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Zip { get; set; }
    public string Country { get; set; }
    public string Phone { get; set; }
    public string Email { get; set; }
    public string Employer { get; set; }
    public Info _Info { get; set; }
}
public class Info
{
    public string License { get; set; }
    public string State { get; set; }
    public string Type { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int Declined { get; set; }
}

I need to also be able to totally remove the Info from an Attendee object before it is converted to JSON.

Or should I create another model without it and somehow transfer the values from one to the other?

What is the simplest way to do this?

Était-ce utile?

La solution

Luckily you don't have circular reference in your model, so you can put [JsonIgnore] on any properties which you don't want in json format:

[JsonIgnore]
public Info _Info { get; set; }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top