2014-10-27 71 views
10

我正在使用Ajax.ActionLink在ASP.NET MVC應用程序中,我使用InsertionMode.Replace,但我看到也有ReplaceWith選項。兩者有什麼區別?一個人取代比另一個更多/更少的東西嗎?我需要我要替換的div完全取代局部視圖。ajax.actionlink替換vs替換

我找不到對谷歌

+0

什麼?你在哪裏找到這個選項?在[documentation](http://msdn.microsoft.com/en-us/library/system.web.mvc.ajax.ajaxoptions.insertionmode(v = vs.118).aspx)中沒有提及它。 – 2014-10-27 12:23:05

+0

我正在輸入VisualStudio,它提出了4個選項,其中一個替換爲 – 2014-10-27 12:23:56

+0

您使用的是哪個版本的MVC?你使用外部庫嗎? – 2014-10-27 12:25:50

回答

19

Replace任何地方的比較將替換爲新內容的內容。 ReplaceWith將取代整個元素。

<body> 
    <div id="myResults"> 
     <p> Results will be displayed here </p> 
    </div> 
</body> 

Replace選項使用ReplaceWith選項靶向靶向myResults

<body> 
    <div id="myResults"> 
     <span>This is the result</span> 
    </div> 
</body> 

從AJAX

<span>This is the result</span> 

響應myResults

<body> 
    <span>This is the result</span> 
</body> 
+0

我看到謝謝! – 2014-10-29 00:47:53

+0

如果Replace的標題爲ReplaceContents,那會更好 – 2017-07-10 18:37:31