Hi im tyring to exlude one property from my model when it reaches my action in the controller (Web API),
i tried [Bind(Exclude ="something")] but it seems that its not apart of .net core api
If you are on ASP.NET Core, Use the Microsoft.AspNetCore.Mvc.ModelBinding.BindNeverAttribute attribute ([BindNever]).
public class ExampleViewModel
{
// ResponseMessage will not participate in model binding.
[BindNever]
public string ResponseMessage { get; set; }
}
"Indicates that a property should be excluded from model binding. When applied to a property, the model binding system excludes that property. When applied to a type, the model binding system excludes all properties that type defines."
[ValidateNever] - (look at the stacktrace for any validation related stack frames). But if you're trying to block based upon that, consider renaming the property to a method GetResponseMessage().[Bind] attribute does not work for the web api if you receive the model as json, try to use [JsonIgnore] on the model properties which need to be excluded:
public class MyModel
{
[JsonIgnore]
public string Name { get; set; }
//...
}
Action:
[HttpPost]
public IActionResult Student([FromBody]MyModel model)
[Bind]only works for multipart/form (MVC actions), not WebAPi which uses json/xml payloads. But if you use proper ViewModel classes (they should only contain values required for a specific action), excluding isn't necessary at all