views:

762

answers:

3

I updated the AJAX scripts and assembly referenced as per release notes. However, IsAjaxRequest still always returns false despite it actually being such a request. How do I resolve this?

A: 

I did not have a problem using RC1 Updated ... As a test I added this action to the Home Controller

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

and this to the Home/Index.aspx file

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

Test Target

Created Views/Home/Test.ascx

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

</br>This is a test

and added the Ajax Javascript Files to the Master Page


In response to comments I added an AjaxForm to the Index.aspx and it worked

<%@ 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&lt;/a&gt;.
    </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>
Matthew
i didnt try with actionlink, but it didnt work with ajax form.
zsharp
+1  A: 

As I understand you are using MS Ajax library. You should update your MicrosoftMvcAjax.js too. It was changed.

zihotki
A: 

I am having the same problem in 1.0.

In fact I just created a new MVC application with the code Matthew provided and Request.IsAjaxRequest() always returns true in this new app too?

KevinUK