views:

18

answers:

1

I have a controller method that returns a jSON object and in one calling situation, it works and in another calling situation, it does not work. When the URL in my browser is this:

http://localhost:65247/Client -- it works.

But, when my url looks like this:

http://localhost:65247/Client/UserAdmin?id=6 -- it DOES NOT work

In a nutshell, clients have users. From within the client, I wish to work on a specific user (this is the UserAdmin view). In this case, the client id is 6. From within the UserAdmin view that was launched with Id=6, I then wish to select a user from a dropdown. The idea was to use javascript and $.getJSON to fetch data for the specific user so as not to have to refresh the entire page. I use this approach in other parts of the app. The only difference I can see is with the URL in the browser. It would appear the presence of parameters via the '?' is futzing things up a bit.

Any ideas??

Thanks in advance.

John

A: 

It is probably a routing issue. Your url need to match a route to work (else the framework doesn't know what action to execute). If you only have the default route your url should be: http://localhost:65247/Client/UserAdmin/6.

My suggestion would be to use the built-in helpers to generate your urls. Then you don't have to change anything if you change your routes. You can use the url helpers like this:

<%=Url.Action("ActionName", "ControllerName")%>
Mattias Jakobsson
Bingo...that was it. The json call only had Admin/GetUser. The correct call is /Admin/GetUser. When the call is in the context of the Admin controller, the first / is not required. However, outside that context, it becomes necessary. Fortunately, having the / always in place works within the Admin context as well.Thank you!!John