我遇到的问题是由于它属于查询字符串,所以
在局部视图页面中,我会获取路径和查询信息:
&X-Requested-With=XMLHttpRequest&_=1462736803425
一直被添加到我的URL中。有没有办法阻止它成为查询字符串,并使用 Ajax.BeginForm
而不进行“hack”操作?@using (Ajax.BeginForm("Search", "Filter", new { Area = "Music" }, new AjaxOptions { HttpMethod = "Get", InsertionMode = InsertionMode.Replace, UpdateTargetId = "body-wrapper", OnSuccess = "updateHistory" }, new { @id = "search-form" }))
{
<div>
<i class="fa fa-search"></i>
<input type="search" placeholder="Search" id="search" name="searchString" />
</div>
}
public ActionResult Search(string searchString)
{
//do stuff
return PartialView();
}
在局部视图页面中,我会获取路径和查询信息:
@Html.HiddenFor(x => Request.Url.PathAndQuery)
Request.Url.PathAndQuery
的值为:http://localhost:1526/Music/Search?searchString=maid&X-Requested-With=XMLHttpRequest&_=1462736803425
然后使用 History.js 更新 URL:
function pushState(target) {
manualStateChange = false;
History.pushState(null, null, $("#Request_Url_PathAndQuery").val());
}
settings
没有data
属性,我也找不到要删除的头文件。 - Martin DawsonAjax.BeginForm
。使用Html.BeginForm
并直接使用jQuery提交表单以进行ajax。但这需要相当多的工作。 - Heretic Monkey