In my MVC app I have a dropdownlist tied to a model like below
class MyObjectViewModel
{
//comes from WebService, but that doesnt matter here
List<PersonViewModel> AllPeople= {person1,person2, etc}
// PersonViewModel has properties like Id, Name, NeedToInform
int SelectedPersonId;
}
@model MyModels.MyObjectViewModel
@Html.DropDownListFor(m=> m.SelectedPersonId,
Model.AllPeople.Select(p=>new SelectListItem{Value = p.Id, Text=p.Name}), new { @class = "form-control", onchange = "process(this.value)" })
The client side code like like below
<script>
process (val) {
console.log(val);
}
</script>
I can get the selected value i.e. Id from PersonViewModel but I need to compare if the selected person from PersonViewModel has the property NeedToInform to be true. Not sure how can we do it in the javascript function, something on these lines
<script>
process (val) {
console.log(val);
//Here I need to compare the model like
// var doWeneedToInform=@Model.AllPeople.Where(x=>x.Id===val).NeedToInform
}
</script>