我遇到的問題是&X-Requested-With=XMLHttpRequest&_=1462736803425
不斷追加到我的url,因爲它是查詢字符串的一部分。有沒有一種方法可以阻止它成爲一個查詢字符串,並在不做'黑客'的情況下做Ajax.BeginForm
?在ajax請求期間從查詢字符串url中刪除'X-Requested-With'
@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:
function pushState(target) {
manualStateChange = false;
History.pushState(null, null, $("#Request_Url_PathAndQuery").val());
}
感謝您的回答,清除了一些東西。 'settings'雖然沒有'data'的屬性,但我找不到要刪除的標題。 –
我能想到的唯一方法就是不使用'Ajax.BeginForm'。使用'Html.BeginForm'並直接使用jQuery來提交帶有Ajax的表單。儘管如此,這是相當多的工作。 –
感謝您的幫助。真的很煩人,這甚至是使用ajax助手的問題。 如果沒有更好的答案出現,我會給你獎金。 –