Wndrr Wndrr - 1 month ago 15
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
Include
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.