I have a SelectList
representing a delivery type for an order.
The delivery type reference data has the usual code/description, but also an additional boolean property which indicates if further information needs to be entered for the type selected.
So for Emergency deliveries additional data is required. The additional data entry fields would be set visible if Emergency was selected, otherwise hidden
My ViewModel
contains <List>ReferenceDeliveryTypes
which contains the 3 properties.
I have created a SelectListItems
from the ViewModel data
@Html.DropDownListFor(model => model.DeliveryTypeCode,
new SelectList(Model.ReferenceDeliveryTypes as System.Collections.IEnumerable,
DeliveryTypeCode, DeliveryTypeDescription), new { id = ddlDeliveryType })
How can I call a jQuery function on change of the delivery type, pass the selected code and check the Model.ReferenceDeliveryTypes
for that code to see if the additional data property is true/false to show/hide the additional fields div
?
I have managed to get the jQuery function called to pass the value.
$(function () {
$('#ddlDeliveryType').change(function () {
var value = $(this).val();
alert(value);
});
});