views:

200

answers:

3

How do I submit disabled input in ASP.NET MVC?

+3  A: 

Typically, if I have a field that is "read-only" but needs to be submitted back to the server, I will make the display disabled (or simply text), but then add a hidden field with the same name. You still need to make sure that the field is not actually modified on the server-side -- just don't update it from the model in your action -- but the model state will still be accurate if there are errors.

tvanfosson
Yes, I was thinking of doing what you're sugesting. But I would had to handle more variables.I'm hopping that may be my post will appear in google and people won't have to suffer, looking for an easy solution.
Sergio
One problem with your solution is that it breaks if javascript is disabled. Injecting the hidden field server-side doesn't have this issue.
tvanfosson
A: 

Can't you make the field readonly="readonly" instead of disabled="disabled"? A readonly field value will be submitted to the server while still being non-editable by the user. A SELECT tag is an exception though.

Darin Dimitrov
A: 

Thanks to everyone:

The way i resolved this:

document.getElementById("Costo").readOnly = true;
document.getElementById("Costo").style.color = "#c0c0c0";

Note:

I got this information on the answer but i got editted.

Sergio