thd
thd

Reputation: 2083

Display a value in a disabled textbox using TextBoxFor

I'm trying to display a disabled textbox with the value 'FL' in it. Somehow the textbox does not have any value when it is displayed, but it is disabled. How do you display a value in a disabled textbox?

<%= Html.TextBoxFor(model => model.State, new { value="FL", disabled="disabled" }) %>

Upvotes: 1

Views: 7828

Answers (2)

Vladimir Shmidt
Vladimir Shmidt

Reputation: 2691

You may write like this:

<%= Html.TextBoxFor(model => model.State, new { @Value="FL", disabled="disabled" }) %>

"@" need, because value is a reserved world

Upvotes: 0

Sunny
Sunny

Reputation: 6336

I think the code:

Html.TextBoxFor(model => model.State, new { disabled="disabled" });

is the code you need.

In the model, set the State = 'FL' & it should work correctly...

HTH.

Upvotes: 2

Related Questions