Click here to Skip to main content
15,885,910 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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" />
}
<br />

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

 
Share this answer
 
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900