升级到RC MVC后,IsAjaxRequest始终为false

时间:2009-02-11 21:03:20

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

我更新了根据发行说明引用的AJAX脚本和程序集。但是,IsAjaxRequest仍然总是返回false,尽管它实际上是这样的请求。我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

据我所知,您正在使用MS Ajax库。您也应该更新您的MicrosoftMvcAjax.js。它被改变了。

答案 1 :(得分:0)

我使用RC1没有问题更新... 作为测试,我将此操作添加到Home Controller

public ActionResult Test()
{
    ifRequest.IsAjaxRequest())
        return PartialView();
    return new EmptyResult();
}

,这是Home / Index.aspx文件

测试目标 创建了Views / Home / Test.ascx     
</br>This is a test

并将Ajax Javascript文件添加到母版页


在回复评论时,我向Index.aspx添加了一个AjaxForm并且它有效

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

<asp:Content ID="indexHead" ContentPlaceHolderID="head" runat="server">
    <title>Home Page</title>
</asp:Content>

<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%= Html.Encode(ViewData["Message"]) %></h2>
    <p>
        To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
    </p>

    <%= Ajax.ActionLink("Test", "Test", new AjaxOptions{ UpdateTargetId="TestTarget", InsertionMode=InsertionMode.InsertAfter} ) %>
    <div id="TestTarget">Test Target</div>

    <% using(Ajax.BeginForm("Test", new AjaxOptions{ UpdateTargetId="TestTarget", InsertionMode=InsertionMode.InsertAfter} ) ){%>

    <button type="submit" >click me</button>

    <% } %>
</asp:Content>
相关问题