Click here to Skip to main content
14,382,682 members
Rate this:
Please Sign up or sign in to vote.
For OnChange event of a dropdown, I am making a ajax call. In the url path, when I give the Controller/Action path it does not hit the method at all.
My code looks like:

function FillHO() {
    //alert('Test');
    var stateId = $('#ddlHO').val();
    $.ajax({
        type: "POST",
        url: '@Url.Action("SetSelectedHO","../../Controllers/ReportsController")' 
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: '{SelectedValue: "' + stateId + '" }',
        success: function (response) {
            alert('Test');
        },
        failure: function (response) {
        alert(response.d);
    }
    });
}


What I have tried:

I have tried '../../Controllers/ReportsController/SetSelectedHO'
'ReportsController/SetSelectedHO'
Posted
Updated 22-Jul-19 0:58am
Comments
santosh.yadav198613 21-Oct-16 11:54am
   
Try calling action from Rest Client and check what you are missing
ZurdoDev 21-Oct-16 12:00pm
   
Implement the error function and see what is happening.
Rate this:
Please Sign up or sign in to vote.

Solution 2

You don't need to specify the path when using Url.Action() method. You need to specify the Controller name instead.

So if you have a Controller that was named ReportsController, then you could try doing something like this:

url: '@(Url.Action("SetSelectedHO","Reports"))'


Note that the suffix Controller was omitted when referencing a Controller name. In other words, your ReportsController can be referenced as Reports only. That's part of the convention.

For more information about the other overload methods of Url.Action() method see:UrlHelper.Action Method (System.Web.Mvc)[^]
   
Comments
Gopal Rajbanshi 22-Jul-19 5:59am
   
useless
CHill60 22-Jul-19 7:22am
   
Useless comment - if you thinkthere is a problem with the solution and are going to go to the trouble of posting a comment at least explain why you think there is a problem
Rate this:
Please Sign up or sign in to vote.

Solution 3

Solved.
It worked without giving an controller reference in url

url: "SetSelectedHO",


Thanks.
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

Use dev tools (F12 in Chrome) to inspect the JavaScript that the client has. You might find the URL supplied for the call is not what you expect it to be.

Does this...

url: '@Url.Action("SetSelectedHO","../../Controllers/ReportsController")'


... generate a valid URL? It looks as though you're setting a literal and not the return value of the @URL.Action method.
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 4

This worked for me:

url:'../Controller/action'
   
Comments
Member 14641047 31-Oct-19 21:20pm
   
Thanks it work for me on laravel, on ubuntu
Rate this:
Please Sign up or sign in to vote.

Solution 6

Thanks for solution 4 its work forme , on laravel on ubuntu
   
Comments
CHill60 1-Nov-19 10:40am
   
If you want to comment on a solution then use the "Have a Question or Comment?" link next to it. Do not post comments or questions as solutions to other members' posts!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100