Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Model binding fails when the posted form data has a key called "Model" #7064

Closed
kshyju opened this issue Nov 18, 2017 · 5 comments
Closed

Model binding fails when the posted form data has a key called "Model" #7064

kshyju opened this issue Nov 18, 2017 · 5 comments
Assignees

Comments

@kshyju
Copy link

kshyju commented Nov 18, 2017

When submit the form and if the form data has an item with key Model, Model binding is failing.

For example, let's say i have a view model like this and I use that class as the param of my http post action method.

public class ModelBinderTestViewModel
{
    public string Name { set; get; }
    public string Model { set; get; }
}

and if i am sending form data like this from my form
Name=Shyju

Model binding works, but when i send

Name:Shyju
Model:Honda

Model binding does not work now.

Here is the link to a minimal sample repo where you can see this issue . Just run the sample app and submit the form and you will see the results in the next view.

Is this a know issue ? If yes, Is there some sort of documentation to advise users to not use Model as a property name.

@Eilon
Copy link
Member

Eilon commented Nov 22, 2017

@dougbu / @rynowak - I believe this is a known limitation. Do we have any reference info on this?

@rynowak
Copy link
Member

rynowak commented Nov 22, 2017

What's the name of the parameter?

@pranavkm
Copy link
Contributor

It's named model - https://github.com/kshyju/TempDataBug/blob/master/TempData/Controllers/ModelBinderTestController.cs#L19. It's the issue where top level parameters cannot share the same name as sub properties.

@dougbu
Copy link
Member

dougbu commented Nov 22, 2017

The documentation, especially the How Model Binding Works sub-section, does describe how request names and values are bound to c# properties. However, the implications of the naming details are not thoroughly spelled out. We thus see a fair number of issues like this one.

The workaround could also be called out in the API Reference e.g. the [ModelBinder] documentation. Right now, the [[ModelBinder(Name = "...")] details] are only boilerplate.

@kshyju
Copy link
Author

kshyju commented Nov 23, 2017

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants