1

我在使用 Ajax.ActionLink 的 updatetargetid 属性在 div 中显示部分视图时遇到问题。这是我的控制器-

    [HandleError]
    public class HomeController : Controller
    {
        static NumberViewModel model = new NumberViewModel();

        public ActionResult Index()
        {

            model.IsDivisibleBy3 = (model.CurrentNumber % 3 == 0);

            if (Request.IsAjaxRequest())
            {
                return PartialView("ViewUserControl1", model);
            }

            return View();
        }

        [ActionName("Increment")]
        public ActionResult Increment()
        {
            model.CurrentNumber++;
            return RedirectToAction("Index");
        }
    }

我的索引视图 -

  <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">

        function ShowResult() {
            var windowWidth = document.documentElement.clientWidth;
            var windowHeight = document.documentElement.clientHeight;
            leftVal = (windowWidth - 655) / 2;
            topVal = (windowHeight - 200) / 2;       

            $('#result').css({
                "left": leftVal,
                "top": topVal
            });
            $('#background').fadeIn("slow");
        }


    </script>
    <div id="background" class="hiddenDiv">
        <div id="result" class="popupBox">
        </div>
    </div>
   <%= Ajax.ActionLink("Show", "Index", new AjaxOptions() { UpdateTargetId="result", OnComplete="ShowResult", HttpMethod="Get" })%> 
   <%= Html.ActionLink("Increment","Increment") %>

</asp:Content>

这适用于 FF,但不适用于 IE6-IE8。

IE 场景- 所以当我点击“显示”时,第一次显示“0 可被 3 整除”。如果单击“增量”,则该数字现在为 1,并且不能被 3 整除。现在,如果我单击“显示”,则显示“0 可被 3 整除”。

在 VS 中保留调试点后,我发现第二次请求根本没有发送到服务器。导致不更新 updatetargetid div。

以前有人遇到过这个问题吗?

4

1 回答 1

3

即缓存重复请求只需将其添加到您的操作方法中:

        Response.CacheControl = "no-cache";
        Response.Cache.SetETag((Guid.NewGuid()).ToString());

所以你将拥有:

[ActionName("Increment")]
    public ActionResult Increment()
    {
        Response.CacheControl = "no-cache";
        Response.Cache.SetETag((Guid.NewGuid()).ToString());
        model.CurrentNumber++;
        return RedirectToAction("Index");
    }
于 2010-07-28T16:34:53.167 回答