If a specific variable is set, I want the specific field to be a text field, if that is not what I want this field to simply display the value, but this value is not editable.
I put some if else logic in my views and the value will not be displayed. Did I miss something?
@{ if (isFlagSet) { Html.TextBoxFor(m => m.HostpitalFinNumber, new { @Value = Model.HostpitalFinNumber }); Html.ValidationMessageFor(m => m.HostpitalFinNumber); } else { Html.DisplayTextFor(m => m.HostpitalFinNumber); } }
Updating ...
I changed my code to
@if (isFlagSet) { Html.TextBoxFor(m => m.HostpitalFinNumber); Html.ValidationMessageFor(m => m.HostpitalFinNumber); } else { Html.DisplayFor(m => m.HostpitalFinNumber); }
Next, HTML is generated. Note how the input value is written for the phone, but not for the hospital fin. Hot sure why this is happening.
<tr><td> <label for="Phone">Phone</label> </td> <td> <input Value="4124880798" id="Phone" name="Phone" type="text" value="4124880798" /> </td></tr> <tr><td> <label for="HostpitalFinNumber">HostpitalFinNumber</label> </td> <td> </td></tr>
ANSWER
I forgot to put @ in front of my html helper and get rid of half-columns.
source share