In following code, it sends an AJAX request to server and it fetches all books. Next it checks total book list length with dropdown list length. Find below steps to get your requirement:
JavaScript:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
var jsonObj = { ClassId : 234 };
alert(JSON.stringify(jsonObj));
$.ajax({
type: "POST",
url: "/Home/BookSet",
data: JSON.stringify(jsonObj),
contentType: "application/json",
datatype: "json",
success: function (bookList) {
if(bookList.length == $("#LstSignInAuthority option").length)
{
}else
{
}
}
});
</script>
Controller action:
[HttpPost]
public ActionResult BookSet(long? ClassId)
{
List<bkselect> Bk = new List<bkselect>();
Bk= (from a in db.Student_Book_Allow_Quantity
where a.Class_Id==ClassId
select new BKselect()
{
Class_Id=a.Class_Id,
Student_Book_Allow_Quantity_Id=a.Student_Book_Allow_Quantity_Id
}).OrderBy(a => a.Class_Id).ToList();
return Json(Bk);
}