I pass null to RepresentativeTypesList viewbag but I'm trying to understand why the line
if ('@representativeTypesList' != null)
is not evaluated correctly and the cursor runs straight to the Html.Raw
part of the view below. I believe I have put the @ escape chars correctly. Any help would be very much appreciated.
@{
var representativeTypesList = @ViewBag.RepresentativeTypesList;
}
@section Header {
<script type="text/javascript">
if ('@representativeTypesList' != null)
{
var array1 = '@Html.Raw(
Json.Encode(
((IEnumerable<RepresentativeTypesModelView>)ViewBag.RepresentativeTypesList).Select(item => new
{
itemValue = (item.Value == null ? "" : item.Value),
itemText = (item.Name == null ? "" : item.Name)
})
)
)';
hdninput1 = $("#txtSalesReps_hdn");
dropdown1 = $("#selSalesReps");
dropdown1.append($("<option />").val('default').text('-- '@lbls.lblSelectOption' --'));
if (array1.length > 0)
{
$.each(array1, function() {
dropdown1.append($("<option />").val(this.itemValue).text(this.itemText));
});
}
}
</script>
}