Wndrr Wndrr - 6 months ago 58
C# Question

Strongly type Bind(Include = **) attribute

Here is the definition of an action from one of my controllers

public ActionResult Login([Bind(Include = "Email,Password")] Utilisateur utilisateur)

I didn't find any way to bind the properties in this way

[Bind(Include = "Utilisateur.Email, Utilisateur.Password")]

Doing this would benefit from Visual Studio's refactoring capabilities and every other aspect of the "strong binding" that it would create.

Do we have to use a string to tell the
property which fields to bind or is there a way to do what I want, with the object's properties ?

I could not find any similar question with an explicit answer.

Answer Source

So it seems that the only way to use the model binder inline, like I want to do it, is by passing the properties names as a string. There is no way, as far as I know, to have strongly typed model binding.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download