ASP.NET MVC 1: Model Binding With Disabled Textbox

Posted by modernzombie on Stack Overflow See other posts from Stack Overflow or by modernzombie
Published on 2010-04-16T13:58:05Z Indexed on 2010/04/16 14:33 UTC
Read the original article Hit count: 919

Filed under:
|
|

I have a textbox that I am defining as

<%= Html.TextBox("Username", Model.Form.Username, 
        new { @class = "textbox", @disabled = "disabled" })%>

In my action

    [AcceptVerbs(HttpVerbs.Post)]
    [ValidateAntiForgeryToken]
    public ActionResult EditLogin(LoginForm post) {

        ...

        return View(model);
    }

post.Username will be blank, all other properties bind correctly, but if I change @disabled="disabled to @readonly="readonly" the username binds properly and everything works.

It looks like model binding ignores values in disabled fields. Is their a way around this? I still need the field's value to bind to the model. I can use readonly but would prefer to use disabled so it is visually apparent to the user that they cannot edit the value of the field.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about mvc