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

Asked

Viewed 2,897 times

8

By creating a CRUD with scalfold in ASP.NET MVC, in POST, we have the following code:

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

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

1 answer

10


Your remark is correct. But this attribute nullifies all Binding already defined and determines that only the properties listed in the attribute will be used. So the action (in this case) cannot unduly popular properties. So if something comes through POST other than Id and Nome will not be considered.

Have you seen any [Bind(Exclude = "AlgumaPropriedade")]? This attribute keeps all properties of Binding except this listed property.

This applies only to the location where the attribute was used.

Can be used as a facilitator or as a security to ensure that anything beyond what is necessary will be inadvertently affected.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.