Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Ajax MVC3
hi,
 
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>
<html>
<head>
    <title>@ViewBag.Title</title>
    <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>
</head>
 
<body>
    @RenderBody()
</body>
</html>
3. The controller:
 public string PartialView1()
        {
            var bajax = Request.IsAjaxRequest(); // always false!!!
            return "wxyz";
        }
Posted 23-Jun-11 21:27pm
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 535
1 Kornfeld Eliyahu Peter 407
2 Maciej Los 369
3 DamithSL 221
4 OriginalGriff 218
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 24 Jun 2011
Copyright © CodeProject, 1999-2014
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