locked
Failed to load resource: the server responded with a status of 404 (Not Found) RRS feed

  • Question

  • User1751533545 posted

    Hi,

    I am having 2 dropdownlist in my view. First one I am filling on load and second one i am trying to fill on selected index change of first one using jquery ajax call. but I am gettin the following error always and its not at all hitting the action method.

    Failed to load resource: the server responded with a status of 404 (Not Found)

    Controller action to be called to fill the second ddl

    public ActionResult FillBranch(Guid DistributorId)
            {
                var branchList = _masterListProvider.GetBranchList(DistributorId).ToList();            
                var result = branchList.ToList();            
                return Json(result, JsonRequestBehavior.AllowGet);
            }

    My JS file which triggers on selected index change of the fist ddl and trying to fill the second ddl using jquery ajax call

      $('#distributor-list').change(function () {
            var selectedindex = $("#distributor-list")[0].selectedIndex;
            debugger;
            if (selectedindex > 0) {
                $("#branch-list").attr('disabled', false);
                var distributorId = $(this).val();
                
                $.ajax({
                    url: '@Url.Action("FillBranch", "Registration")',
                    type: "POST",
                    data: { 'DistributorId': distributorId },
                    dataType: "json",
                    traditional: true,
                    contentType: "application/json; charset=utf-8",
                    success: function (data) {
                        alert('success');
                    },
                    error: function () {
                        alert("An error has occured!!!");
                    }
                });
            }
        });
      

    But its always giving the mentioned error and not at all hitting the action.

    And the second question is once i get the result from the action(after resolving the first issue) how can i append the seonc ddl with the result. The first element should be "Please Choose".

    Please help me...Thanks in advance

    Vidya

    Tuesday, September 15, 2015 12:39 AM

Answers

All replies

  • User603616845 posted

    Hi,

    404 literally means that file was not found. It's simple as that. Check if the URL is right, and there are no rediretions being done(

    check this url is exists and try to change it

    from

    url: '@Url.Action("FillBranch", "Registration")'

    to

    url: "/Registration/FillBranch",

    for more info refer this article

    http://www.codeproject.com/Articles/730953/Cascading-Dropdown-List-With-MVC-LINQ-to-SQL-and-A

    Hope this will help you.

    thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 15, 2015 1:30 AM
  • User1751533545 posted

    Hi Mukesh,

    Thanks a lot for your response. I have tried the changes u have suggested , but its not working fine.

    Actually this project is in sitecore mvc.

    And one more thing i could find is the "not found" url is referring some other controller name eventhough i ahve given my controller name.

    http://website/sitecore/service/notfound.aspx?item=%2fregistrationcontroller%2ffillbranch&user=sitecore%5cadmin&site=website

    why its adding "f" as a prefix of my registration controller ?

    Can u pls suggest mean altervative.

    Thanks,

    Priya

    Tuesday, September 15, 2015 2:41 AM
  • User1751533545 posted

    Hi ,

    Thanks a lot for the reply and the link u suggested is having good ideas and now iam able to hit the controller action. But still one more issue, i am getting the deatisl from db and passing to the success part of the ajax call, but its not listing in the second ddl.Its not even looping through the each function.

    Can u pls suggest me where i am going wrong.

       public ActionResult FillBranch(Guid DistributorId)
            {
                var branchList = _masterListProvider.GetBranchList(DistributorId).ToList();    
            
               // var result = branchList.ToList();    
                var result = (from s in branchList
                              select new
                              {
                                  id = s.id,
                                  name = s.Value
                              }).ToList();        
                return Json(result, JsonRequestBehavior.AllowGet);
            }
    @Html.DropDownListFor(x => x.BranchId, Model.Branches,  new { @class = "col-lg-12 col-md-12 col-sm-12 col-xs-12 form-comtrol valid", @id = "branch-list" })
                                            @Html.ValidationMessageFor(x => x.BranchId, "", new { @class = "error" })
    $.ajax({
                    cache: false,
                    url: "/RMRegistration/FillBranch",
                    type: "GET",
                    data: { 'DistributorId': distributorId },
                    dataType: "json",
                    traditional: true,
                    contentType: "application/json; charset=utf-8",
                    
                    success: function (data) {
                        debugger;
                        //alert('success');
                        ddlbrnach.html('');
                        $.each(data, function (id, option) {
                            ddlbrnach.append($('<option></option>').val(option.id).html(option.name));
                        });
                    },
                    error: function () {
                        alert("An error has occured!!!");
                    }
                });

    Thanks in advance

    Vidya

    Tuesday, September 15, 2015 5:21 AM