I write code from the article and and there is:
public IActionResult Create([Bind(Include="Imie,Nazwisko,Stanowisko,Wiek")] Pracownik pracownik)
{
blablablab
}
I want to compile but it shows error.
include is not a valid named attribute argument.
But in the internet I saw a code similar to my code. Someone explain to me what's going on? Of course, I am using asp.net 5.
Decimals while a basic type are not a primitive type and hence cannot be represented in metadata which prevents it from being an attribute parameter.
The [BindProperty] is an instruction to the model binding framework to bind the underlying property with the matching request parameter.
[FromBody] attributeThe ASP.NET Core runtime delegates the responsibility of reading the body to an input formatter. Input formatters are explained later in this article. When [FromBody] is applied to a complex type parameter, any binding source attributes applied to its properties are ignored.
How does model binding work in ASP.NET Core MVC. In an empty project, change Startup class to add services and middleware for MVC. Add the following code to HomeController, demonstrating binding of simple types. Add the following code to HomeController, demonstrating binding of complex types.
In Asp.Net Core, the Include
property no longer has a setter. You need to pass the list of bound properties using the constructor:
public BindAttribute(params string[] include)
{
Include = include;
}
And in your case:
public IActionResult Create([Bind("Imie","Nazwisko","Wiek")] Pracownik pracownik)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With