Jquery InsertionMode.Replace如何在Ajax.begin上工作

Jquery InsertionMode.Replace如何在Ajax.begin上工作,jquery,asp.net-mvc-3,ajax.beginform,Jquery,Asp.net Mvc 3,Ajax.beginform,我的asp.net mvc视图中有以下Ajax.beginform,其中Ajax调用的结果将替换,如下所示:- @using (Ajax.BeginForm("Search", "Patient", new AjaxOptions { HttpMethod = "GET", InsertionMode = InsertionMode.Replace, UpdateTargetId = "searcharea", LoadingElementId = "pr

我的asp.net mvc视图中有以下
Ajax.beginform
,其中Ajax调用的结果将替换
,如下所示:-

@using (Ajax.BeginForm("Search", "Patient",
    new AjaxOptions
{
    HttpMethod = "GET",
    InsertionMode = InsertionMode.Replace,
    UpdateTargetId = "searcharea",
    LoadingElementId = "progress2"
}))
{
   <table >

 <tr>

        <th>
         Searching By First Name (English) :-
        </th>
        <th>
          <input type="text" name="firstname"  />
        </th></tr>
      <tr>

        <th>
         Searching By Family Name (English) :-
        </th>
        <th>
          <input type="text" name="familyname"  />
        </th></tr>

      <input type="submit" value="Search      " /></th><th></th></tr>
  </table>

}

<div id = "progress2">
<img src= "@Url.Content("~/Content/images/Ajax-loader-bar.gif") ">
</div>
<p>
<div id= "searcharea">
</div>
@使用(Ajax.BeginForm(“搜索”、“患者”),
新选择
{
HttpMethod=“GET”,
InsertionMode=InsertionMode.Replace,
UpdateTargetId=“searcharea”,
LoadingElementId=“progress2”
}))
{
按名字搜索(英文):-
按姓氏搜索(英文):-
}

因此,在开始时,我认为我只能执行一次搜索,因为
将被ajax调用的结果替换,此后将不再是Avilbe,如果我尝试执行另一个ajax调用,将不会有更多的
来替换结果

但实际发生的情况是,我能够进行多次搜索,没有任何问题,这意味着
InsertionMode.Replace
不会替换DOM元素,它只会在这个DOM中插入ajax调用的结果,,因为我无法理解如何多次引用DOM元素,即使它已被我的第一个ajax调用所取代???!!有人能解释这是怎么发生的吗?
BR

您误解了
插入模式。请替换
。它将用
UpdateTargetId
替换您指定的HTML元素内部的所有内容,而不是元素本身

这和

$("#searcharea").html(newHTMLcontent);

由于您提到的原因,破坏它所使用的元素的插入模式不会非常有用:您只能使用它一次。

是的,我知道insertionmode.replace应该用方法调用的结果替换UpdateTargetid,但是我可以多次引用UpdateTargetid,这意味着UpdateTargetid实际上没有被替换,所以我试图理解发生了什么…请重新阅读我的答案。插入模式替换不会替换UpdateTargetId。它会替换UpdateTargetId中的所有内容。>破坏它所使用的元素的插入模式不会很有用为什么?我真的错过了用更新版本替换局部视图的模式:我可以简单地用一些div来包装局部视图。现在我必须找到所有使用此局部视图的位置,并包装RenderPartial调用:\Yea,我同意Alleo。使用MVC已经有一段时间了,但现在才意识到,Replace是内部的,而不是全部。嗯,很奇怪。你可以很容易地和jQueryHey绑定到动态对象。我知道我参加晚会已经很晚了。我正在推广2015年2月发布的MVC 5.2.3,您可以将InsertionMode指定为“ReplaceWith”,它可以实现您所描述的功能(替换DOM节点本身,而不仅仅是内部html)。它可能已经包含在早期版本中,但我知道它至少在5.2.3中。