我有一个包含下拉菜单的视图,当我选择一个特定选项时,我想在部分视图中显示返回的数据。不惜一切代价,ajax功能无法正常工作。我正在使用VS 2013 MVC 4。
试图从http://code.jquery.com/jquery-latest.min.js更改最新的jquery,但仍然无法正常工作。 Ajax调用无法正常工作。从最近的第一天开始伤了我的头。
查看:
@model IEnumerable<TTracking.CareWebService.ClinicGroup>
@using System.Globalization;
@{
ViewBag.Title = "Appointment";
Layout = "~/Views/Shared/_LayoutWebsite.cshtml";
}
<h2></h2>
<script type="text/javascript">
$(function () {
$("#CategoryID").change( function (event) {
var userId = $(this).val();
$.ajax({
url: "@Url.Action("GetDoctors", "Controller")",
data: { id : userId },
type: "GET",
dataType: "html",
success: function (data) {
$("#divPartialView").html( data );
}
});
});
});
</script>
<div class="dropdown">
@Html.DropDownList("CategoryID",
(List<SelectListItem>)ViewBag.Categories, "Select Clinic")
</div>
<div id="divPartialView">
</div>
返回部分视图的控制器:
public PartialViewResult GetDoctors(int id)
{
var res = new CWS.DoctorsCollection();
try
{
CWS.CWSSoapClient cl = new
CWS.CWSSoapClient();
res = cl.getDoctorsByClinicGroup(id.ToString(),
"sercuritykey");
}
catch (Exception ex)
{
}
return PartialView("DoctorsList",res.Doctors);
}