views:

96

answers:

1

Im having a really hard time understanding routing.

Please help me with this problem.

Each of my controllers have these three actions right now

Users have Index, Create and Edit

Locations have Index, Create and Edit

Companies have Index, Create and Edit

The thing is, it all gets done through ajax.

I have jquery ui tabs with two tabs for each, Create and Edit So the Index method is always the one that gets called for action links. and inside this main view is that you can call(by clicking on the tab icon) the other methods that return an ajax view that gets output into the jqeury tab (I hope thats clear)

I have a sidebar with links to the controllers. and to specific methods of these controllers. The wanted behavior is that it should actually go into the Index Method and then with some logic autoload the wanted tab.

It all works just fine right now. But my urls are horrible. To get to the create method for Users I have to go this url

http://localhost/Users/Index/1

http://localhost/Users/Index/2

I want the behavior of these links to be remapped to these links

http://localhost/Users/Create

http://localhost/Users/Edit

So even though it seems as if you are calling the Create method of the controller you are actualling always calling the Index Method.... (I know how to transform Create into "1" and Edit into two, so dont worry about that part

Hope thats clear. Thanks in advance

Edit:

Just realized that this might not be possible cause then when I actually need to call the methods (with ajax) it wont know what to do.... am I correct?

A: 

Without seeing your controller action, you should be able to add a route something like this:

routes.MapRoute("myroute","users/{option}",new {controller="Users",action="Index"});
mxmissile
But how will it know how to distinguish when I want to call the real method (through ajax) and the Index Method with the option parameter??...This is so hard to explain :S
NachoF
Can you post your controller Action then maybe we will have a better idea.
mxmissile