Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i create the script call function in mvc controller , it's working good in visual studio, but when i converted to IIS website , all website working good else casecading dropdownlist ,,,

my code (

=========================================================

function


public ActionResult FillDept(string level)
  {

         var depart = db.Departments.Where(c => c.LevelId == level);
             return Json(depart, JsonRequestBehavior.AllowGet);

  }






script in html view

<script>

    function FillDept() {
        var levelId = $('#Level').val();
        $.ajax({
            url: '/Trainees/FillDept',
            type: "GET",
            dataType: "JSON",
            data: { Level: levelId },
            success: function (depart) {
                $("#Department").html(""); // clear before appending new list
                $.each(depart, function (i, department) {
                    $("#Department").append(
                        $('<option></option>').val(department.DeptId).html(department.DeptName))


                });
            }
        });
    }
</script>







dropdwonlist


 @Html.LabelFor(m => m.Level, new { @class = "control-label col-md-1" })
 <div class="col-md-3 jumbotron">
     @Html.DropDownListFor(m => m.Level,
        new SelectList(ViewBag.LevelList, "LevelId", "LevelName"),
        "level",
       new { @class = "form-control", @onchange = "FillDept()" })
     @Html.ValidationMessageFor(m => m.Level, "", new { @class = "text-danger" })

 </div>



 @Html.LabelFor(m => m.Department, new { @class = "control-label col-md-1" })
 <div class="col-md-3 jumbotron">
     @Html.DropDownListFor(m => m.Department,
new SelectList(Enumerable.Empty<SelectListItem>(), "DeptId", "DeptName"),
       "department", new { @class = "form-control" })
     @Html.ValidationMessageFor(m => m.Department, "", new { @class = "text-danger" })

 </div>




)

What I have tried:

Hi there , i need to help please ..
asp.net MVC code first
Posted
Updated 3-Oct-18 6:22am
v2
Comments
j snooze 3-Oct-18 17:31pm    
could be CORS (something similar to this...https://stackoverflow.com/questions/36543244/cross-origin-in-ajax-call-using-asp-net-mvc) I can't say for sure obviously, but its somewhere to start looking.
Christian Graus 4-Oct-18 1:41am    
This question makes no sense. What does 'not working' mean? What do you see in the debug window?

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

  Print Answers RSS


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