2014-10-27 68 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