Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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 :

HTML
<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:
C#
@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:

C#
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));
        }
Posted
Updated 23-Oct-15 5:11am
v5
Comments
F-ES Sitecore 23-Oct-15 10:59am    
You can't use AutoPostBack on MVC and your onchange event if for the client-side but there is no js method called FilterIndex, that is a controller action and you can't call server code from client js, and you also have a jquery event attached, basically the code is a bit of a mess.

Google how "implement ajax dropdown asp.net mvc" for examples of what you're trying to do.
Asmaa Rashad 23-Oct-15 11:16am    
but during debugging i found that it it's already calls the function FilterdIndex in the controller and executes it correctly
Maciej Los 25-Oct-15 3:55am    
Try:
<script src="<%= Url.Content("~/Scripts/jquery-1.4.1.min.js") %>" type="text/javascript" />
Asmaa Rashad 25-Oct-15 7:36am    
Still having the same problem
Asmaa Rashad 25-Oct-15 7:48am    
the exception 0x800a138f is removed but another one appears but i can't access where is it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900