我的控制器中有以下代码
public ActionResult Index(string searchTerm=null)
{ System.Threading.Thread.Sleep(5000);
var accountdefinition = repository.FindAccountDefinition(searchTerm).ToList();
if (Request.IsAjaxRequest())
{ return PartialView("_CustomerTable",accountdefinition); }
return View(accountdefinition);
}
但是如果我使用 Ajax.beginform 调用上述操作方法,那么 Request.IsAjaxRequest 将返回 false 并且不会返回部分视图
@using (Ajax.BeginForm(
new AjaxOptions{
HttpMethod= "get",
InsertionMode=InsertionMode.Replace,
LoadingElementId = "progress",
UpdateTargetId="customerTable"}))
{
<div style="float:right">Search <input placeholder="Search by name.." name="searchTerm" type="text"> <input class="btn btn-success" type="submit" value="search" /></div>
}
<div id = "progress" class="loadingimage">
<img src="~/Content/Ajax-loader-bar.gif" />
</div>