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'?

Answers


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


Need Your Help

get previous next row using PDO to create links

php mysql sql pdo

i've got some bad sytax in my query where i'm trying to create 'prev_id' to pull into the $row result link. any ideas on a better way of doing this?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.