0
我试图用Json显示每个学生的详细信息,我认为它不会去ajax
部分。Json GET未在弹出框中显示详细信息
它显示了id
,当我console.log()
他们url
,但我得到这个错误信息的AJAX部分
我不知道有什么遗漏或哪里的问题?
这是我HTML链接
@Html.ActionLink("Details", "StudentDetails", new { id = item.ID }, new { @class = "modalDetails", @id = item.ID })
脚本
<script type="text/javascript">
$(function() {
$(".modalDetails").click(function (e) {
e.preventDefault(); //stop the default action upon click
var id = $(this).attr('id');
console.log(id);
var url = $(this).attr("href");
console.log(url);
$.ajax({
type: 'GET',
data: { id: id },
dataType: "json",
url: url,
success: function (data) {
$(".modalDetails").append('<span> First Name: ' + data.firstName + '</span></br>');
console.log("success");
}
});
$('#myModal').modal('show'); // show the modal pop up
});
});
</script>
StudentController
public JsonResult StudentDetails(int id)
{
Student student = studentRepository.GetStudentByID(id);
var json = new{
firstName = student.FirstMidName
};
return Json(json, JsonRequestBehavior.AllowGet);
}
不应该你的网址是这样的http:// localhost:52245/Student/StudentDetails /?id = 23不是这个http:// localhost:52245/Student/StudentDetails/23?id = 23。 –