2017-03-09 16 views
0

私はJsonで各Studentの詳細を表示しようとしていますが、それはajax部分にはないと思います。Json GETはポップアップで詳細を表示していません

それはidと私はそれらをconsole.log()urlを示しているが、私はAjaxの一部

Error image

私が欠落している場合や、問題があるだかわからないため、このエラーメッセージが表示されますか?

この私の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); 
     } 
+1

http:// localhost:52245/Student/StudentDetails /?id = 23このhttp:// localhost:52245/Student/StudentDetails/23?id = 23のようにはなりません。 –

答えて

1

すべて私は解決策を構築する必要があり、appendの詳細をmodal-bodyに追加する必要があることを除いて、問題はありませんでした。時にはそれは単純な修正です。

関連する問題