【发布时间】:2016-09-03 09:41:45
【问题描述】:
我遇到的问题是&X-Requested-With=XMLHttpRequest&_=1462736803425 一直被附加到我的网址,因为它是查询字符串的一部分。有没有办法可以阻止它成为查询字符串并在不执行“hack”的情况下执行Ajax.BeginForm?
@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());
}
【问题讨论】:
标签: javascript c# jquery ajax asp.net-mvc