I need to hide/show some controls in cshtml based on what is selected in a dropdown list. I want to be able hide/show these sections before the value of the dropdown list is sent back to model and saved. How do I do this? I looked at these questions but had no luck question1 question2
@model Models.EmployerModel
@{ ViewBag.Title = "Index"; }
<div>
<p class="validateTips">
Enter the new employment details.</p>
<fieldset>
<table>
<tr>
<td>
<label>
<b>Employment Type:</b></label>
</td>
<td>
@Html.DropDownList("EmploymentTypeDrp")
</td>
</tr>
<tr>
<td>
<label>
<b>Job Title:</b></label>
</td>
<td>
@Html.TextBoxFor(m => m.JobTitle, new { Value = @Model.JobTitle })
</td>
</tr>
</table>
</fieldset>
</div>
So what I need is that based on what is selected in EmploymentTypeDrp, Job Title be visible or not. I have a JQuery bit to update the model based on new information.
.change()event of the dropdownlist and show/hide the elements). But showing/hiding them does not change what is posted back to the controller so not sure what your trying to achieve.new { Value = @Model.JobTitle }- the value is already set by theTextBoxFor()method and you should never try and override thevalueattribute