user3889193
user3889193

Reputation: 63

Conditionally disable textbox in Razor view

Its a quick question.

@Html.TextBoxFor(model => model.VIN, string.IsNullOrEmpty(Model.VIN) ? new { @class = "required Vin" } : new { @disabled = "disabled" })

I get the error that Type of expression can not be determined because there is no implicit conversion anonymous type #1 and anonymous type #2.

Is there a way to conditionally disable text box?

Upvotes: 3

Views: 3749

Answers (1)

Dennis R
Dennis R

Reputation: 3237

Try something like

 @Html.TextBoxFor(model => model.VIN, string.IsNullOrEmpty(Model.VIN) ? new { @class = "required Vin" } : (object)new { disabled = "disabled" })

Upvotes: 5

Related Questions