Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ExceptPropertiesAttribute : ActionFilterAttribute
- {
- private IEnumerable<string> _propertiesKeys;
- public ExceptPropertiesAttribute(string commaSeperatedPropertiesKeys)
- {
- if (!string.IsNullOrEmpty(commaSeperatedPropertiesKeys))
- {
- this._propertiesKeys = commaSeperatedPropertiesKeys.Split(',');
- }
- }
- public override void OnActionExecuting(ActionExecutingContext actionContext)
- {
- if (this._propertiesKeys != null)
- {
- foreach (var propertyKey in this._propertiesKeys)
- {
- if (actionContext.ModelState.ContainsKey(propertyKey))
- {
- actionContext.ModelState.Remove(propertyKey);
- }
- }
- }
- }
- }
- [ExceptPropertiesAttribute("Id")]
- public ActionResult Post([FromBody] MyModelDTO itemDTO)
- {
- //code
- }
- public ActionResult Put([FromBody] MyModelDTO itemDTO)
- {
- //code
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement