2011-04-14 4 views
1

일부 지연된 데이터가 표시 될 수있는 ASP.Net 페이지에서 고급 사양을 수행하고 있습니다.새로 고침없이 페이지에 새 데이터로드

페이지가로드되면 표시되는 초기 데이터는 로컬 데이터베이스에서 제공됩니다 (프리젠 테이션이 빠름). 내가 원하는 것은 외출하고 (내가 가진 다른 서비스에서) 업데이트 된 데이터를 찾는 별도의 프로세스입니다. 이것은 더 많은 시간이 소요되지만 아이디어는 데이터를 제시하고 새로운 데이터가 발견되면 기존 페이지 상단에 바로 추가합니다.

이 작업을 수행하는 방법에 대한 권장 사항이 필요합니다.

이 기술 범위는 ASP.Net 4.0, C# MVC3 및 HTML5입니다.

감사합니다.

+2

당신이 찾고있는 용어는 AJAX입니다. –

답변

2

AJAX with jQuery이 작업을 수행하는 좋은 방법입니다. 는 DOM이로드되면 다음

<div id="result" data-remote-url="@Url.Action("Load", "SomeController")"></div> 

과 : 그래서 예를 들어, 당신은 당신의 마크 업에 내용 자리의 사업부를 넣을 수있는로드 컨트롤러 액션이 원격 서비스와 통신 처리됩니다

$(function() { 
    $.ajax({ 
     url: $('#result').data('remote-url'), 
     type: 'POST', 
     beforeSend: function() { 
      // TODO: you could show an AJAX loading spinner 
      // to indicate to the user that there is an ongoing 
      // operation so that he doesn't run out of patience 
     }, 
     complete: function() { 
      // this will be executed no matter whether the AJAX request 
      // succeeds or fails => you could hide the spinner here 
     }, 
     success: function(result) { 
      // In case of success update the corresponding div with 
      // the results returned by the controller action 
      $('#result').html(result); 
     }, 
     error: function() { 
      // something went wrong => inform the user 
      // in the gentler possible manner and remember 
      // that he spent some of his precious time waiting 
      // for those results 
     } 
    }); 
}); 

데이터가 포함 된 부분도 반환 : 이제

public ActionResult Load() 
{ 
    var model = ... go ahead and fetch the model from the remote service 
    return PartialView(model); 
} 

를 데이터의 당신이 광고를 취할 수 I/O를 많이 가져 오는이 경우 원격 소스에서 데이터를 가져 오는 오랜 시간 동안 작업자 쓰레드가 위험 해지는 것을 피할 수있는 I/O 완료 포트 asynchronous controllers.

관련 문제