Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jose Badia 13 posts 156 karma points
    Aug 21, 2015 @ 12:57
    Jose Badia
    0

    Ajax call to Surface Controller Action 404 Error

    I'm tying to implement a cascading dropdown on a form. When the user selects a value from one select list, an AJAX call is made to retrieve the data to fill a second dropdown. This is an Umbraco form in a partial view rendered with an @Html.Action and a child [HttpGet] method to populate it. This part is working, but mention it for reference.

    In my view, I try to issue an AJAX post request to '/Umbraco/Surface/{surface-controller-name}/{action-method-name}" when the dropdown changes, but I get a 404 Not Found error.

    I'm new to Umbraco. Any help would be much appreciated.

    In Surface Controller...

    public class PricingRequestFormSurfaceController : SurfaceController
        {
            public ActionResult TestAjaxCall()
            {
                var result = "Test result from controller";
                return Json(result);
            }
        }
    

    In my view...

    $(stateDropdown).change(function () {
        alert('dropdown change detected');
        $.ajax({
            type: "POST",
            url: "/Umbraco/Surface/PricingRequestFormSurfaceController/TestAjaxCall/",
            datatype: 'json',
            contentType: 'application/json; charset=utf-8',
            success: function (result) {
                alert('success!');
            },
            error: function (result) {
                alert(JSON.stringify(result));
            }
        });
    });
    
  • Jose Badia 13 posts 156 karma points
    Aug 21, 2015 @ 18:06
    Jose Badia
    102

    I figured out what was happening. It is a bit embarrassing, but I hope it is useful to someone else in the future. I had to take "Controller" out of the url.

    url: "/Umbraco/Surface/PricingRequestFormSurface/TestAjaxCall/",
    

    I figured it out by listing out all the routes using the following code:

    @foreach(System.Web.Routing.Route route in RouteTable.Routes)
    {
        @route.Url<br />
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft