Comparing value from model with the value from view
$("#lstIncludedOBNCategories").change(function () {
var rightSelectedIndex = $("#lstIncludedOBNCategories").get(0).selectedIndex;
<% if(Model.ObnCategoriesDTO.where(x => x.OBNCategoryID == %> rightSelectedIndex
<% ) %> -----I SHOULD DO SOMETHING HERE
});
I do not know whether I can use if statement as below.
<% if(Model.ObnCategoriesDTO.where(x => x.OBNCategoryID == %> rightSelectedIndex <%)%&开发者_如何学编程gt;
It is not letting me do compare like this. Can anyone help me with this.
This won't work as you've got it. You are trying to use a client side value "rightSelectedIndex" and insert it into server side scripting (your C# if statement).
The problem is, your if statement has already processed before the page was sent to the client, so that javascript can't possibly have run yet. You will need to rethink your code here and possibly make an ajax post to send that rightSelectedIndex back to the server to find the Categories you are looking for.
精彩评论