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();
return "wxyz";
}