我有一个Ajax表单,如下所示:
@using (Ajax.BeginForm("AjaxSerchResult", "Search", new { area = string.Empty }, new AjaxOptions() { HttpMethod = "Get", UpdateTargetId = "Results", LoadingElementId = "Loading" }, new { id = "Search" })
{
//Fields go here
}
问题是:如何使用我使用AJAX发送的参数更新浏览器网址?
如果要使用Ajax.BeginForm()
,请使用“ OnSuccess”属性和benalman的插件,因为如果没有javascript,将无法更改url
网址更改的演示(需要jQuery 1.9)
@using(Ajax.BeginForm(
"AjaxSerchResult",
"Search",
new { area = string.Empty },
new AjaxOptions(){
HttpMethod = "Get",
UpdateTargetId = "Results",
LoadingElementId = "Loading",
OnSuccess = "changeUrl(data)"
},
new { id = "Search" }))
{
//Fields go here
}
和javascript:
<script>
function changeUrl(data) {
//if you are using benalman's plugin with jQuery 1.9
location.hash = "#my_hash";
}
</script>
注意:但是由于使用$.browser
了benalman的插件(已从jQuery 1.9中删除),我建议使用window.location.hash = "#my_url";
或window.location.replace("#my_url");
代替location.hash = "#my_url";
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句