1

Here is my dummy model:

class Customer {
    string Name;

    // View Model part
    bool IsDisabled;
}

Here is my view:

@using (Html.BeginForm(actionName, controllerName))
{
   @Html.TextBoxFor( c => c.Name, new { disabled = ***) })

   <input type="submit" value="Submit" />
}

So the question is: How can i bind the 'isDisabled' property of my viewmodel to the 'disabled' attribute of my textbox? i.e. What should stand in the place of '*' ?

2 Answers 2

2
@Html.TextBoxFor(c => c.Name, Model.IsDisabled ? new { disabled = "disabled" } : null)
Sign up to request clarification or add additional context in comments.

Comments

1
@Html.TextBoxFor( c => c.Name, new { disabled = c.IsDisabled) })

1 Comment

Well, first of all, if you try to run it, you will get a runtime error. Furthermore in plain HTML, you can't write <input disabled="true" or disabled="false".

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.