简体   繁体   中英

IsAjaxRequest is always false after upgrade to RC MVC

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?

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

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

Test Target Created Views/Home/Test.ascx
 </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</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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM