Samantha J T Star
Samantha J T Star

Reputation: 32808

How can I do model binding for an action in MVC?

On my HTML I have something like this:

<input id="City_Name" name="City.Name" size="15" type="text" value="" />
<input disabled="disabled" id="Location" name="Location" size="15" type="text" value="" />

The first field binds to the City.Name in my model. However the second field needs to bind to City.Location.

Is there a simple way that I can make this bind to the correct field in my model?

Upvotes: 1

Views: 125

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038930

I would recommend you fixing your markup and having the field name City.Location instead of Location. Always use editor templates, they will generate proper field names for your inputs so that you don't have to worry about it. As a side note your field is marked as disabled which means that its value will never be sent to the server no matter how it is named.

Upvotes: 2

Related Questions