我有一个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发送的params更新浏览器URL?
最佳答案
如果你想使用Ajax.BeginForm(),你会使用“OnSuccess”属性和benalman’s plugin,因为没有javascript你将无法更改网址
demo of url changing(需要jQuery 1.9)
@using(Ajax.BeginForm(
"AjaxSerchResult",new AjaxOptions(){
HttpMethod = "Get",LoadingElementId = "Loading",OnSuccess = "changeUrl(data)"
},new { id = "Search" }))
{
//Fields go here
}
和javascript:
注意:但是由于在benalman的插件中使用$.browser(已经从jQuery 1.9中删除),我建议使用window.location.hash =“#my_url”;或window.location.replace(“#my_url”);而不是location.hash =“#my_url”;