Click here to Skip to main content
11,934,443 members (40,877 online)
Rate this:
Please Sign up or sign in to vote.
See more: Ajax MVC3

I'm a newbie on MVC3.
In my first project, i encounted a wired problem that when i'm using Ajax.BeginForm in view, the controller cannot get the Ajax request, that.., the Request.IsAjaxRequest() returns false. I almostly freak out with it.
Could someone help me?
1. My View page:

    ViewBag.Title = "Home Page";
    Layout = "~/views/shared/_Layout.cshtml";
<div id="tardiv"></div>    
@using (Ajax.BeginForm("PartialView1", new AjaxOptions(){ UpdateTargetId = "tardiv"}))
    <input type="submit" value="Refresh" />
2. The _layout.cshtml:
<!DOCTYPE html>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/microsoftajax.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
3. The controller:
public string PartialView1()
           var bajax = Request.IsAjaxRequest(); // always false!!!
           return "wxyz";
Posted 23-Jun-11 21:27pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Thank you very much, sir.
I found the reason is "UnobtrusiveJavaScriptEnabled" is set to "true" in web.config.
It 's ok when set to false.
I don't understand mvc3 well and need more effort.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.1 | Last Updated 24 Jun 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100