Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8894625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:32:56+00:00 2026-06-14T23:32:56+00:00

I am having a (I think stupid) problem. I have a controller, Index method,

  • 0

I am having a (I think stupid) problem.

I have a controller, Index method, and its view has some JQuery functions.

It works fine, and the JQuery methods work perfectly.

the link I use is

http://localhost:54209/TestInput/

but if I put

http://localhost:54209/TestInput/Index

the JQuery functions do not work. From what I know they should act exactly the same.

That is the only thing that I change

I really appreciate your help. This has been driving me crazy during the last couple of hours!

For example, This is my script

<script>
  $(document).ready(function() {
    $('select#testCategoriesUniqueId').change(function() {
        var testCategory = $(this).val();
        $.ajaxSetup({ cache: false });
         alert ("AAA");
        $.ajax({
            url: "TestInput/listTestCases/" + testCategory,
            dataType: "json",
            type: 'post',
            success: function(data) {
                $("#testCasesUniqueId").removeOption(/./);
                for (var i = 0; i < data.length; i++) {
                    var val = data[i].Value;
                    var text = data[i].Text;
                    $("#testCasesUniqueId").addOption(val, text, false);
                }
            }
        });
    });
});

In both cases, I get an alert, but In the second link, I can not call the controller.

It doesn’t call the listTestCases method of my controller.

Update:

So I tried to use parameters instead of the exact link,
I still have the problem, I got both sources, and got a diff, the only difference is

<form name="aspnetForm" method="post" action="Index" id="aspnetForm">

vs.

<form name="aspnetForm" method="post" action="TestInput" id="aspnetForm">

and

<form action="/TestInput/Index" method="post">

vs.

<form action="/TestInput" method="post">

Which I beleive has nothing to do with the jQuery.

I still see the laert in both cases.
but the JQuery works in ~/TestInput and not with the ~/TestInput/Index.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:32:58+00:00Added an answer on June 14, 2026 at 11:32 pm

    this is why you shouldn’t hardcode urls in an asp.net mvc app.
    your problem is that your ajax url is a relative url.
    when you load the page using url http://example.com/TestInput/ the ajax url ends up being something like http://example.com/TestInput/TestInput/listTestCases or maybe http://example.com/TestInput/listTestCases

    When you use the url http://example.com/TestInput/Index your ajax url ends up being http://example.com/TestInput/Index/TestInput/listTestCases

    Insetead you should use one of the Html helpers to declare your ajax url like this. (using razor syntax)

    <script>
      $(document).ready(function() {
        $('select#testCategoriesUniqueId').change(function() {
            var testCategory = $(this).val();
            $.ajaxSetup({ cache: false });
             alert ("AAA");
            $.ajax({
                url: "@Url.Action("listTestCases")"+ "/" + testCategory,
                dataType: "json",
                type: 'post',
                success: function(data) {
                    $("#testCasesUniqueId").removeOption(/./);
                    for (var i = 0; i < data.length; i++) {
                        var val = data[i].Value;
                        var text = data[i].Text;
                        $("#testCasesUniqueId").addOption(val, text, false);
                    }
                }
            });
        });
    });
    </script>
    

    Update for ASPX View Engine:

    If you are using the ASPX view engine insted of Razor use this syntax.

    <script>
      $(document).ready(function() {
        $('select#testCategoriesUniqueId').change(function() {
            var testCategory = $(this).val();
            $.ajaxSetup({ cache: false });
             alert ("AAA");
            $.ajax({
                url: "<%=Url.Action("listTestCases")%>"+ "/" + testCategory,
                dataType: "json",
                type: 'post',
                success: function(data) {
                    $("#testCasesUniqueId").removeOption(/./);
                    for (var i = 0; i < data.length; i++) {
                        var val = data[i].Value;
                        var text = data[i].Text;
                        $("#testCasesUniqueId").addOption(val, text, false);
                    }
                }
            });
        });
    });
    </script>
    

    Be sure to use Firebug or F12 dev tools to double check the exact url you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a problem redrawing a QWidget window after its size has been
I'm not good at JS and I'm having some -I hope- stupid problem I'm
I think I am having a problem with the scope of 'this' when needing
I think I might be having a stack overflow problem or something similar in
Having an issue here that I have tried everything I can think of but
I think this should be simple but I am having some difficulty implementing it.
I have been having some trouble with matplotlib since I started using python. When
Ok, I fear that this is just me having forgotten some small stupid thing
I am having some performance problems that have left me baffled. I am using
I'm having this problem: I have two Google maps in one page, showing just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.