What is Bind (Include="Property") used for?

6

When we create a CRUD with scalfold in ASP.NET MVC, in the POST methods, we have the following code:

 public ActionResult Create([Bind(Include = "Id,Nome")] Grupo grupo) {...}

What is this [Bind] used for? When we use Grupo grupo , is Bind no longer done automatically?

    
asked by anonymous 29.12.2014 / 23:31

1 answer

7

Your observation is correct. But this attribute overrides any binding already defined and determines that only the properties listed in the attribute will be used. So the action (in this case) will not be able to improperly property properties. So if something comes up with POST other than Id and Nome they will not be considered.

Have you ever seen any [Bind(Exclude = "AlgumaPropriedade")] ? This attribute holds all binding properties except this property listed.

This applies only to where the attribute was used.

Can be used as a facilitator or as a security to ensure that nothing more than what is needed will be inadvertently affected.

    
29.12.2014 / 23:47