I need to enable/disable certain controls in the view depending on a condition. I try to use the answer in this link here but it did not work in my case. Currently I'm using the (pseudo) code as show below, which works, but it is insane to use it, since there are many entries like that. I need a solution like the one in here
@{ if (Model.ChargeCost == true)
{
@Html.TextBoxFor(m => m.Cost, new { @id="myId", @class = "form-control" })
}
else
{
@Html.TextBoxFor(m => m.Cost, new { @id = "myId", @class = "form-control", disabled = "disabled" })
}
UPDATE: I APOLOGIZE FOR THE MISUNDERSTANDING BUT THE CODE THAT I HAVE AS AN EXAMPLE WORKS PERFECTLY. WHAT I NEED IS SOMEONE WHO ACTUALLY HAS A DEEPER UNDERSTANDING OF MVC5 AND C# THAT CAN OPTIMIZE THIS TERRIBLE CODE, SINCE I HAVE MANY MORE CONDITIONS LIKE THIS ONE IN THE VIEW..
Aucun commentaire:
Enregistrer un commentaire