theandroid
theandroid

Reputation: 943

MVC C# disabled bool gets saved as false

I have a MVC where some of the bools are Checked (set to true) and disabled. When I POST the form, they always gets passed in as False. How do I determine what the original value of the bool, in this case TRUE?

Upvotes: 0

Views: 248

Answers (2)

user47589
user47589

Reputation:

When I POST the form, they always gets passed in as False.

Actually, they aren't being sent at all. You can see this if you look at the JSON sent on the wire using a tool like Fiddler.

Disabled field controls are omitted from form data. Make it readonly instead of disabled.

See the documentation:

Indicates whether the element is disabled or not. If this attribute is set to true the element is disabled. Disabled elements are usually drawn with grayed-out text. If the element is disabled, it does not respond to user actions, it cannot be focused, and the command event will not fire. In the case of form elements, it will not be submitted

Compare this to readonly:

If set to true, then the user cannot change the value of the element. However, the value may still be modified by a script.

Upvotes: 2

King Clauber
King Clauber

Reputation: 39

I got this same error when programming in ASP3. You may have to re-enable the checkbox right before posting the page.

Or you can change it to readonly as Amy said.

Upvotes: 0

Related Questions