0

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

John Saunders
  • 159,224
  • 26
  • 237
  • 393
Pawan
  • 1,912
  • 4
  • 19
  • 25

1 Answers1

0

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:

  1. Use Html.ActionLink()
  2. Use a form + <input type="submit" />
  3. 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.

Community
  • 1
  • 1
Kirk Woll
  • 73,473
  • 21
  • 178
  • 189
  • I just tired to use the without the window.location but it did not update the URL. Can you suggest what could be the best way to achieve this result or some kind of an example. – Pawan Apr 16 '11 at 10:10
  • @Pawan, why did you try it "without the `window.location`"? If you are still under the misapprehension that you can modify the URL without reloading the page then please desist. :) That is categorically impossible. – Kirk Woll Apr 16 '11 at 14:08