【问题标题】:Ajax.ActionLink not workingAjax.ActionLink 不工作
【发布时间】:2014-11-25 08:37:01
【问题描述】:

我正在尝试在 MVC4 项目中使用 Ajax.ActionLink。我已将这两个包含在我的布局页面中。

@Scripts.Render("~/Scripts/jquery-1.7.1.js")
@Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.min.js")

在我的关于视图中,我有以下代码

<h3>Server Time</h3>

<div id="timeDisplay">
    Time shown here
</div>
<div>
    @Ajax.ActionLink("Click here for time", "ServerTime", new AjaxOptions{HttpMethod="GET", UpdateTargetId="timeDisplay"})

</div>

服务器时间操作方法只是将最新时间作为长时间字符串返回 第一次一切正常,但是当我第二次单击链接时,没有任何反应,没有调用服务器方法。我检查了 FIDDLER 并没有发送 Http 消息。是因为它使用缓存的响应。如何让它再次调用该方法

【问题讨论】:

    标签: ajax asp.net-mvc-4 actionlink


    【解决方案1】:

    试着用OutputCache(NoStore = true ..装饰你的ActionResult

    [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
    public ActionResult ServerTime()
    {
        ...
    }
    

    或者尝试在您的 AjaxOptions 上使用 HttpMethod = "POST"

     @Ajax.ActionLink("Click here for time", "ServerTime", new AjaxOptions{HttpMethod="POST", UpdateTargetId="timeDisplay"})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-29
      • 1970-01-01
      • 1970-01-01
      • 2011-03-19
      • 2012-02-05
      • 1970-01-01
      • 2012-03-13
      • 1970-01-01
      相关资源
      最近更新 更多