0

Instead of have "disabled="true"" hardcoded in the TextBoxFor element, I want it pulled from the Model. The model property (Model.InvoicedApprovedBy) would be set to "" (enabled) or "disabled="disabled" (disabled)

<%= Html.TextBoxFor(m => m.WorkingModel.Detail.ApprovedBy, new { id = "InvoiceApprovedBy", disabled="true", style = "width: 203px; " })%>

I want to do something like this:

<%= Html.TextBoxFor(m => m.WorkingModel.Detail.ApprovedBy, new { id = "InvoiceApprovedBy", Model.InvoicedApprovedBy, style = "width: 203px; " })%>

It sets a html attribute called "InvoicedApprovedBy" instead of just placing the string "disabled="disabled"" into it. How to I get it to place the string?

0

1 Answer 1

1
 <%= Html.TextBoxFor(m => m.WorkingModel.Detail.ApprovedBy, new { id = "InvoiceApprovedBy",  disabled = Model.InvoicedApprovedBy, style = "width: 203px; " })%>

You won't need to set the model property to "disabled=disabled", just "disabled".

Sign up to request clarification or add additional context in comments.

2 Comments

The element will always be disabled in this case. I want to be able to have no "disabled =" as well.
The you're gonna have to get ugly: <input type="text" @(Model.Disabled ? "disabled=disabled" : "") /> you'll need a bool to do this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.