Update Urls in MVC 3 during json Request
I am having a default page Controller like
http://localhost/Test/Index.mvc/Index
开发者_开发知识库I have a div which has nested drop-down's. on my last drop-down using jquery Ajax i call a action method GetTime( string temp 1, string temp 2).But my url is still the same as above and it never changes
I need the url to change to
http://localhost/Test/Index.mvc/Time?temp1=10&temp2=20
I added a new route map in global.ascx
routes.MapRoute(
"Test",
"{controller}.mvc/{action}/{id}",
new {controller ="Index", action="GetTime",id=" "});
when i use firebug to debug the urls are perfectly fine and i get the desired results but i need the urls to change for the case of bookmarking.
Thanks, Pawan
You mention that you are using jQuery and Ajax to invoke the action. That means that it's happening client-side. The only way to update the URL is to actually redirect to that URL. You can't modify it, and nothing you do client-side short of the redirect is going to do any good.
In other words, you need to either:
- Use
Html.ActionLink()
- Use a form +
<input type="submit" />
- Use javascript:
window.location = @Url.Action(...);
Keep in mind that if you use option three, your action will execute all over again if you are still performing that ajax call -- probably not what you want.
精彩评论