小编Dav*_*man的帖子

jQuery Mobile/MVC:使用RedirectToAction获取浏览器URL

我的第一篇文章......

当我使用RedirectToAction时,浏览器中的url不会更改.我怎样才能做到这一点?

使用Web表单10多年后,我正在切换到ASP.NET MVC 3.0(也使用jQuery Mobile).我大约需要8个星期的时间,经过几本书并且谷歌搜索答案之后,我才会干嘛.

我在Global.asax中定义了一个路由:

routes.MapRoute(
"Routes",
"{controller}/{action}/{id}",
new { controller = "Shopping", action = "Index", id = UrlParameter.Optional }
Run Code Online (Sandbox Code Playgroud)

我有一个包含以下操作的ShoppingController:

public ActionResult Cart() {...}

public ActionResult Products(string externalId) {...}

[HttpPost]
public ActionResult Products(List<ProductModel> productModels)
{
    // do stuff
    return RedirectToAction("Cart");
}
Run Code Online (Sandbox Code Playgroud)

当我进行get和post(带有RedirectToAction的帖子)时的url总是:

/Shopping/Products?ExternalId=GenAdmin
Run Code Online (Sandbox Code Playgroud)

在post和RedirectToAction之后,我希望浏览器中的url更改为:

/Shopping/Cart
Run Code Online (Sandbox Code Playgroud)

我尝试过Redirect和RedirectToRoute,但得到了相同的结果.

任何帮助将不胜感激.

[更新] 我发现jQuery Mobile AJAX帖子是这里的罪魁祸首.如果我关闭jQuery Mobile的AJAX就可以了.

<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
    // do not handle links via ajax by default
    $(document).bind("mobileinit", function () { $.mobile.ajaxEnabled = false; });
</script>
<link rel="stylesheet" …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc-routing jquery-mobile asp.net-mvc-3

28
推荐指数
3
解决办法
1万
查看次数