2011-08-13 3 views
0

나는 다음과 같은 조치 선언 :문제 JQuery와와의 asp.net MVC에서 부분보기 렌더링은

public ActionResult EditComment(int id) 
     { 
      try 
      { 
       var comment = commentRepository.GetItem(id); 

       return PartialView("Comment",comment); 
      } 
      catch 
      { 
       return Content("Error!"); 
      } 
     } 

을 그리고 이것은 좀보기에 무엇을 가지고 :

..... 
<%:Html.ActionLink(GlobalText.Edit,"#", null, new { @class="EditLink",id=item.CommentID})%> 
..... 

<div id="link"> 

</div> 

<script type="text/javascript"> 
    $(document).ready(function() { 
     $('.EditLink').click(function() { 
      var idval = this.id; 
      $.ajax({ 
       url: "/Articles/EditComment", 
       data: { id: idval }, 
       success: function (mydata) { 
        $("#link").empty().append(mydata); 
       }, 
       type: "POST" 
      }); 
      return false; 
     }); 
    }); 

'EditLink'클래스가있는 링크를 클릭하면 응용 프로그램이 실행 결과를 처리하지만 '$ ("# link"). empty(). append (mydata);' jquery의 작동하지 않으며, 나는 아무것도 얻지 않는다! .

+1

대신 .empty() (을 MyData) 추가 변경하려고; 왜 그냥 .html (mydata); ? –

+0

저에게 잘 어울립니다 ... JS 콘솔에 오류가 있습니까? 또한 스크립트 태그를 끝내시겠습니까? –

+0

'John Kurlak'>> 그래, 끝냈어. 또한 '$ ("# link"). empty(). append (mydata);를 포함하는 줄에 중단 점을 넣을 때 파이어 버그에 파이어 버그가 설치되어 있습니다. 그것은 거기서 멈추지 않는다. 'Kahoun'>> 작동하지 않습니다 –

답변

0

public ActionResult - to PartialResult EditComment(int id)

$(document).ready(function() { 
    $(".EditLink").each(function(){ 
     $(this).click(function() { 
     var idval = this.id; 
     $.ajax({ 
      url: "/Articles/EditComment", 
      data: { id: idval }, 
      success: function (mydata) { 
       $("#link").empty().append(mydata); 
      }, 
      type: "POST" 
     }) 
    }); 

가}

+0

Jquery에 초보자이기 때문에 '$ (문서)'대신 '무엇을 사용해야합니까?' ? –

+0

$ (document) .ready – Devson

+0

의 문제가 아쉽습니다. EditComment/View .....에서 문제는 $ ('. EditLink')를 선택하면 .each()를 사용해야한다는 것입니다. . like this $ ('. EditLink'). each (function() {this.click (......)}) – Devson

관련 문제