2013-08-05 33 views
1

嗯,從本身重新加載部分視圖INSIDE

我有一個PartialView,它用一個複雜的模型生成一個VIEW。 我有一個按鈕,我想完全再生我PartialView

@if (!Model.editFlag) 
{ 
<button id="EditButton" class='btn btn-small'>Edit</button> 
} 
else 
{ 
<button class='btn btn-small'>Update</button> 
} 

這是我的AJAX調用

$.ajax(
{ 
    type: "POST", 
    url: "@Url.Action("DeviceDetails_Edit","DeviceLayout")" , 
    data: 
    { 
     DeviceID: '@Model.DeviceID', 
     DeviceName: '@Model.DeviceName', 
     DeviceDescription: '@Model.DeviceDescription', 
     editFlag: '@Model.editFlag', 
    }, 
    cache:false, 
    success: function(html) 
     { 
      alert('success'); 
     }, 
     error: function(e) 
      { 
      alert("errorn"); 
      } 

}); 
}); 

和控制器,我有一個ActionResult,誰返回一個局部視圖與我的新的具體模型 返回PartialView(「_ DeviceDetails」,模型);

進入我的看法,存在着更多更PartialView`s

我怎樣才能解決這個問題呢?

+0

你是什麼意思時,你說:使用jQuery,您可以在點擊事件按鈕清除div元素,樣品

<div id="myView"></div> 

使用jQuery,您可以用empty方法清除DIV「進入我的看法,存在更多partialViews的「和什麼是問題或錯誤? –

+0

這方面並不重要(我的頁面中有更多的PartialView),我想要的是當我按下按鈕時從另一個操作完全重新加載我的部分視圖 – Alynuzzu

+0

感謝Felipe Oriani! – Alynuzzu

回答

2

我會假設你已經在你的頁面上有一個div。

$("button").click (function (e) { 

    // clear the html on the div 
    $("#myDiv").empty(); 


    // make a post to reload the div: 
    $.ajax(
    { 
     type: "POST", 
     url: "@Url.Action("DeviceDetails_Edit","DeviceLayout")" , 
     data: 
     { 
      DeviceID: '@Model.DeviceID', 
      DeviceName: '@Model.DeviceName', 
      DeviceDescription: '@Model.DeviceDescription', 
      editFlag: '@Model.editFlag', 
     }, 
     cache:false, 
     success:function(html) 
       { 
        // fill the div with the html returned by action 
        $("#myView").html(html); 
       }, 
     error: function(e) 
       { 
        alert("errorn"); 
       } 
    }); 

}); 
+0

它是外面的看法。但如何重新加載部分視圖的部分視圖? – Kate

+0

在此部分視圖中添加一個JavaScript以加載另一個視圖。看看javascript(jquery)代碼。 –