さて、方向性を示しましょう。簡単なので、jquery のコードをいくつか示します。さあ行こう。
HTML
<div id="SomeContent"> </div>
あなたの見解では
$(function(){ // this runs on on page load
LoadData('#SomeContent', @Url.Action("ActionName","ControllerName"));
});
JavaScriptライブラリファイルで
function LoadData(target, url){
$.ajax({
beforeSend: startAnimation(target),
url : url,
success : function(result){ $(target).html(result); },
complete : stopAnimation(target)
});
}
function startAnimation(target){
//..add a loading image on top of the target
}
function stopAnimation(target){
// remove the animation gif or stop the spinning, etc.
}
サーバー側のコード
public ActionResult ActionName() {
... do things to get your model populated ...
return PartialView("SomeView", yourmodel);
}
追加の考え:
- この大まかなコードは、部分ビューを div にロードします。DOM の準備ができると、非同期呼び出しが開始されます。
- jquery ajax のドキュメントについては、 http: //api.jquery.com/jQuery.ajax/ を参照してください。
- とても簡単で小さいので、spin.js を使用して読み込みアイコンを表示するのが好きです。