2017-02-23 34 views
-1

我嘗試過不同的方法來刷新MVC中的特定分區。 1.使用HTML動作鏈接 2. Ajax動作鏈接 3.方法 請幫我解決這個問題。如何在使用MVC時刷新特定分區

我的代碼如下:

<script src="~/scripts/jquery.unobtrusive-ajax.js"></script> 
<script> 
    function updateAsyncCategoryUpdate() { 
     var url = '/Home/HomePage'; 

     $.ajax({ 
      url: url, 

      //data: { value: '1234' }, //if there are any parameters 
      dataType: "html", //or some other type 
      success: function() { 
       window.location.reload(true); 
       // or something in that area, maybe with the 'data' 
      }, 
      error: function() { 
       //some derp 
      } 
     }); 
    } 
</script>` 

@Ajax.ActionLink(item.Name, "HomePage", new { CATEGORy = item.Name }, new AjaxOptions {HttpMethod="GET", OnSuccess = "updateAsyncCategoryUpdate('item.Name')" }) 
+0

'成功:功能(數據){$(someDiv)。html的(數據); }' –

回答

0

你的腳本函數沒有參數,你送Item.Name吧(雖然你不使用這個參數在腳本中! )

首先,爲updateAsyncCategoryUpdate函數定義參數。

Secomd,一個容器元素(如格)添加到特定的ID您的頁面(resultDiv爲例)並更換憑證的成功代碼與此:

success: function(result){ 
var myDiv = $('#resultDiv'); 
myDiv.empty(); 
myDiv.prepend(result); 
} 
1

您可以將成功的功能。

這將替換DIV

success: function (data) 
{ 
    $('#divSelector').html(data); 
} 

這種內容的追加DIV的內容

success: function (data) 
{ 
    $('#divSelector').append(data); 
}