Search code examples
textboxasp.net-mvc-5conditional-statementsenable-if

change the state of a textbox depending on which view is called


I'm new to MVC, and would like to know in C# mvc5, what kind of code I would need to use, if I wanted to change the state of a textbox from enabled to disabled and vice versa based on which view is calling the partial view.


Solution

  • Try to add something like this in your tag: @('Condition Here') ? disabled:"disabled" : ""

    Or:

    object mode = ('Condition Here') ? null : new {disabled = "disabled" };
       @Html.TextBoxFor(x => x.YourPropertyHere, mode)