c# - How to exclude certain properties from binding in ASP.NET Web Api -
How do I exclude certain properties, or clearly specify which model properties will be tied to web API model binder ? With the formation of another model class in ASP.NET MVC, something similar to If you are using JSON, then you For XML, you can use Data Contracts and Datamember attributes. More information about both. CreateProduct ([Bin (Include = "name, category" product product) and after that the repetition of all the verification attributes for the original Do the model.
// EF Ententement Model Class Public Class User {Public Ent Id (Get; Set;} // Skip Public String Name {get; set;} // Public string Include email {get; set;} // included in public Post the public HTTPPRPRESS PUBNATION message (User User) {if (this.ModelState.) • Send the message to the email and email property to the child ISAdmin {get; set;} // include only for advertising} // HTTP post: / API / IsValid) {return.Request.CreateErrorResponse (this.ModelState);} Add this.db.us.us (user); this.db.SaveChanges (); return it, request.release rationpace (html.txt code. OK); } // HTTP post: / api / admin / users | The names, email and properties of ISDMM Return only the public HTTPPREPS postmessage post (user user) {if (! This.ModelState.IsValid). Return this return.Request.CreateErrorResponse (this.ModelState); } This.db. Add (user); this.db.SaveChanges (); Turn it back. request. Create Response (HTTP.txt Code. OK)); }
[JsonIgnore Can use] attribute to decorate your model properties.
Public Sector Products {[JasonInjor] Public Ent ID {get; Set; } // should leave the public string name {get; Set; } // should be included in the public string category {get; Set; } / / [JSNighior] Public Ink Download {get; Set; } // should be excluded}
Comments
Post a Comment