Hello ,
iam working using MVC and Entity framework , I have a view that displsy data of "BloodDonors" table from database and i can filter them by their blood group value that selected by dropdownlist ,so i want after choosing specific blood group i call the controller function that filters and pass them to the view for displaying.But after runing i get that exception:[0x800a138f - Microsoft JScript runtime error: Object expected] beacause of JS code that i used in the view . Any help to handle that exception?
this is the JS code that i use to call controller function in the view :
<script src="~/Scripts/jquery-1.8.16.min.js" type="text/javascript"></script>
<script src="~/Scripts/jquery-1.8.16.js" type="text/javascript"></script>
<script>
debugger;
$(document).ready(function () {
$("#DONOR_BLOOD_GROUPE_ID").change(function () {
$.ajax({
type: 'POST',
url: '@Url.Action("FilterdIndex", "DONOR")',
dataType: 'html',
data: { id: $("#DONOR_BLOOD_GROUPE_ID").val() },
success: function (data) {
},
error: function (ex) {
alert('Failed to retrieve' + ex);
}
});
return false;
})
});
</script>
the dropdownllist that call onchange func:
@Html.DropDownList("DONOR_BLOOD_GROUPE_ID", null, "--Select--", new { onchange="FilterdIndex(this.value)" , AutoPostBack="True"})
and this is the controller function that i call using JS code:
public ViewResult FilterdIndex(int id)
{
ViewBag.DONOR_BLOOD_GROUPE_ID = new SelectList(db.BLOOD_GROUP, "GROUP_ID", "GROUP_NAME");
return View(db.DONOR.Where(u => u.DONOR_ID == id));
}