0

我有两个 div 标签。单击第一个 div 标签时,会发生 AJAX 调用,第二个 div 标签会替换第一个。

我在第二个 div 标签中有后退按钮。单击后退按钮时,我应该能够看到第一个 div 标签被第二个 div 标签替换。

这是我的剃刀代码:

<div id="tag1" onclick="show_placedetail()>
    <a href="#" class="button button-small button-style3 butcurve-sml">View</a>
</div>

<div id="tag2">
    <a href="#" class="button button-small button-style4 butcurve-sml" onclick="show_placelist()">Back</a>
</div>

这是我的 AJAX 调用:

@using (Ajax.BeginForm("Detail", "Places", new AjaxOptions
    {
        HttpMethod = "POST",
        InsertionMode = InsertionMode.Replace,
        UpdateTargetId = "tag1",
    }, new { name = "PlaceDetailsForm", id = "PlaceDetailsForm" }))
{
    <input type="hidden" name="locationId" id="locationId" />
    <input type="hidden" name="distance" id="distance" />
}

这是我的 JQuery:

function show_placedetail() {
    $('#tag1').hide();
    $('#PlaceDetailsForm').submit();
}

function show_placelist() {
    $('#tag2').hide();
    $('#tag1').show();
}

我检查了第一个 div 标记的 .html() 内容在 AJAX 调用后被清空。

为了显示在 AJAX 期间被另一个 div 标签替换的 div 标签,我应该怎么做?我是否需要调用另一个 AJAX 调用来显示第一个 div 内容?

友善的建议。

提前致谢。

4

1 回答 1

0

我纠正了我的错误。

Actually, I am replacing my first div by AJAX. Hence, it wont be available if I try to show it again. So I created a parent tag and put both of the tags within it. And I changes my InsertionMode option to InsertAfter.

Now it is working fine.

Here is my updated Razor code:

<div id="parent">
  <div id="tag1" onclick="show_placedetail()>
      <a href="#" class="button button-small button-style3 butcurve-sml">View</a>
  </div>

  <div id="tag2">
      <a href="#" class="button button-small button-style4 butcurve-sml"   onclick="show_placelist()">Back</a>
  </div>
</div>

And my updated AJAX code:

@using (Ajax.BeginForm("Detail", "Places", new AjaxOptions
    {
        HttpMethod = "POST",
        InsertionMode = InsertionMode.InsertAfter,
        UpdateTargetId = "parent",
    }, new { name = "PlaceDetailsForm", id = "PlaceDetailsForm" }))
{
    <input type="hidden" name="locationId" id="locationId" />
    <input type="hidden" name="distance" id="distance" />
}
于 2014-03-29T06:29:58.340 回答