2
I am creating a project in ASP.NET Core MVC for learning purposes. In a certain part of the Microsoft guide when the technique of scaffold to generate the controller and the views corresponding to the actions of controller, I came across an instruction in some methods that left me doubtful in well confused.
See below the method Create
as an example:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("ID,Title,ReleaseDate,Genre,Price")] Movie movie)
{
if (ModelState.IsValid)
{
_context.Add(movie);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(movie);
}
See the statement before the parameter declaration movie
. It is at this point that my doubt arose and left me confused.
Doubts
- What kind of characteristic is instruction
[Bind("ID,Title,ReleaseDate,Genre,Price")]
passed at signature of the Create method? - What would be the purpose of this feature when used in a method?
I know it serves to define which attributes of the object should be passed in Httppost, similarly there is another instruction to delete attributes from
Bind
done during the Post on the object. I do not have more information to formulate a decent answer, so I leave it as a comment only =] https://msdn.microsoft.com/en-us/library/system.web.mvc.bindattribute(v=vs.118). aspx– Rovann Linhalis