asp.net-mvc-3 – jQuery Mobile/MVC:使用RedirectToAction获取
我的第一篇文章…
当我使用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 } 我有一个ShoppingController与这些操作: public ActionResult Cart() {...} public ActionResult Products(string externalId) {...} [HttpPost] public ActionResult Products(List<ProductModel> productModels) { // do stuff return RedirectToAction("Cart"); } url当我做一个get和post(与post的RedirectToAction)总是: /Shopping/Products?ExternalId=GenAdmin 后post和RedirectToAction我想要的浏览器中的url更改为: /Shopping/Cart 我试过Redirect和RedirectToRoute但得到相同的结果。 任何帮助将不胜感激。 [更新] <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" href="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.css" /> 上述脚本的顺序很重要。我不得不包括脚本到jQuery首先,然后包括脚本禁用jQuery Mobile的使用AJAX,然后包括脚本到jQuery Mobile。 我仍然想找到一种方法来使用AJAX并正确更新url。或者至少能够调用jQuery Mobile的“加载”消息(或者烘焙自己的)。 解决方法
我想我找到了一个答案。埋在深深的
jQuery Mobile documentation,有信息关于设置data-url在div与data-role =“页面”。当我这样做,我得到了漂亮的jQuery Mobile AJAX东西(页面加载消息,页面转换),我得到的URL在浏览器更新正确。
基本上,这是我怎么做… [HttpPost] public ActionResult Products(...) { // ... add products to cart TempData["DataUrl"] = "data-url="/Cart""; return RedirectToAction("Index","Cart"); } 然后在我的布局页面我有这个…. <div data-role="page" data-theme="c" @TempData["DataUrl"]> 在我的HttpPost操作我现在设置TempData [“DataUrl”],因此对于那些页面,它设置和填充在布局页面。 “获取”操作不设置TempData [“DataUrl”],因此它不会填充在布局页面上的那些架构。 唯一不适合这种情况的是当你右键单击…查看源代码…在浏览器中,html不总是你的页面,这是不寻常的AJAX 。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |