user20358
user20358

Reputation: 14736

How to set disable attribute for Html.TextBoxFor based on a property value associated to that textbox

I tried using this example here like this

<%: Html.TextBoxFor(model => model.MyList[0].FirstName, model.MyList[0].IsEnabled ? (object)new { disabled = "disabled" } : new { })%>

but that gave me an error

"The name model doesn't exist in the current context"

Is there a way to do this in vanilla asp.net MVC 3 without using an if else condition?

Thanks for your time...

Upvotes: 0

Views: 1692

Answers (2)

user20358
user20358

Reputation: 14736

I fixed this: I should use the actual model I am passing in to the view. Notice the change in Caps on the second parameter.

<%: Html.TextBoxFor(model => model.MyList[0].FirstName, Model.MyList[0].IsEnabled ? (object)new { disabled = "disabled" } : new { })%>

Upvotes: 1

James Osborn
James Osborn

Reputation: 1275

Just quickly checking for this error message suggests that maybe your web.config is broken.

The name 'model' does not exist in current context in MVC3

Upvotes: 0

Related Questions