Asp.net core model doesn't bind from form Asp.net core model doesn't bind from form asp.net asp.net

Asp.net core model doesn't bind from form


Be careful not to give an action parameter a name that is the same as a model property or the binder will attempt to bind to the parameter and fail.

public async Task<IActionResult> Index( EmailModel email ){ ... }public class EmailModel{ public string Email { get; set; } }

Change the actions parameter 'email' to a different name and it will bind as expected.

public async Task<IActionResult> Index( EmailModel uniqueName ){ ... }


I'm not sure it is same case, but I had same problem and nothing really looks to work for me.
The problem in my case was that I had a property called Model in my view model class

public string Model { get; set; }

When I renamed the property to ModelName everything was working fine again, even without FromForm attribute.

Looks like some special property names could be a bit of a problem for asp.net mvc model binding.

So, my advice is to check your model properties and maybe try renaming them one by one in order to check if the problem is there.

Hope this helps.


I'm having the same problemthis docs helps me to understand Model Bindinghttps://docs.asp.net/en/latest/mvc/models/model-binding.html

I solved my problem by making sure that the property name is exact match in form field nameand I also add [FromForm] attribute to specify exactly the binding source.