开发者

ASP MVC Controller Method not always called from $.getJSON request

开发者 https://www.devze.com 2022-12-22 14:35 出处:网络
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:

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, t开发者_运维问答he 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


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")%>
0

精彩评论

暂无评论...
验证码 换一张
取 消