Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. public class ExceptPropertiesAttribute : ActionFilterAttribute
  2. {
  3. private IEnumerable<string> _propertiesKeys;
  4.  
  5. public ExceptPropertiesAttribute(string commaSeperatedPropertiesKeys)
  6. {
  7. if (!string.IsNullOrEmpty(commaSeperatedPropertiesKeys))
  8. {
  9. this._propertiesKeys = commaSeperatedPropertiesKeys.Split(',');
  10. }
  11. }
  12.  
  13. public override void OnActionExecuting(ActionExecutingContext actionContext)
  14. {
  15. if (this._propertiesKeys != null)
  16. {
  17. foreach (var propertyKey in this._propertiesKeys)
  18. {
  19. if (actionContext.ModelState.ContainsKey(propertyKey))
  20. {
  21. actionContext.ModelState.Remove(propertyKey);
  22. }
  23. }
  24. }
  25. }
  26. }
  27.  
  28. [ExceptPropertiesAttribute("Id")]
  29. public ActionResult Post([FromBody] MyModelDTO itemDTO)
  30. {
  31. //code
  32. }
  33.  
  34. public ActionResult Put([FromBody] MyModelDTO itemDTO)
  35. {
  36. //code
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement