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 20: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 OriginalGriff 373
1 Sergey Alexandrovich Kryukov 197
2 Richard Deeming 160
3 PhilLenoir 120
4 RyanDev 115
0 Sergey Alexandrovich Kryukov 6,405
1 OriginalGriff 5,798
2 CPallini 2,473
3 Richard MacCutchan 1,647
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | 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