jquery – MVC Ajax.BeginForm – 成功获取请求后在浏览器中更新URL

我有一个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”;

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...