$ .getJSON(url)没有移动到控制器

时间:2015-11-06 06:18:17

标签: json asp.net-mvc-4

我正在我的MVC中开发我的应用程序。我在我的应用程序中使用级联下拉列表。在选择一个我有2个下拉列表时,一个是位置,另一个是员工。在选择位置时,应在员工下拉列表中提取特定员工。我使用json结果来检索员工。

我的代码是

查看页面

@Html.DropDownList("location", ViewBag.Location as SelectList, "Select the Location", new { id = "location" })

<div id=" employeediv" style="width:600px; height:50px">
    <div style="float:left">
        <label> Employee:</label>
    </div>
    <div style="margin-left:220px">
        <select id="Employee" name="employee" style="width:150px"></select>
    </div>
</div>

脚本:

@section scripts{
   <script type="text/javascript">

    $('#location').change(function () {
            @*var url = '@Url.Action("Employe", "Appt")';*@
           //var url = "/Appt/Employee/"
           debugger;
           $.getJSON('/Appt/Employee/' + $('#location').val(), function (data) {

               var item = '<option> Any </option>';
               $.each(data, function (i, employee) {

                   item += "<option value ='" + employee.Value + "'>" + employee.Text +
                       "</option>";


               });

               $("#employee").html(items);

           });




       });

</script>

}

控制器代码

public ActionResult CalendarView(int? id, int? CustomerUserid)
        {
            tblBusinessCategory bc = new tblBusinessCategory();

          ViewBag.Location = new SelectList(from s in db.tblBusinessLocations
                                            where s.BusinessID == id
                                            join loc in db.tblLocations
                                                on s.LocID equals loc.LocationId
                                            select loc.LocationName);
         return View();
}


  public JsonResult Employee(int id)
        {

            SYTEntities db = new SYTEntities();
            var emp = from s in db.Employees
                      where s.LocationId == id 
                      select s;
            return Json(new SelectList(emp.ToArray(), "EmpId", "EmpName"), JsonRequestBehavior.AllowGet);
        }

我的问题是,在更改位置网址时,不会重定向到控制器,而是从其范围中输出 $。getJSON(&#39; / Appt / Employee /&#39; + $(&#39;#location&#39;)。val(),功能

任何人都可以帮我解决这个问题吗?

感谢。

0 个答案:

没有答案