John Livermore
John Livermore

Reputation: 31313

controlling what properties serialize to Json

I want to control what properties are sent in my Json result.

Given...

    public class Result
    {
        public string SendThisProperty { get; set; }
        public string DontSendThisProperty { get; set; }
    }

    public virtual ActionResult Index()
    { 
        var result = new Result();
        return Json(result);
    }

Is there a way to only return the property 'SendThisProperty'?

Upvotes: 1

Views: 47

Answers (1)

Madd0g
Madd0g

Reputation: 4001

Add a [ScriptIgnore] to the property declarations that you don't want in the json, that should do the trick

Upvotes: 2

Related Questions