More in this section
Forums / Developing with Sitefinity / AJAX Post From Button Click On Custom MVC Widget Returns 404

AJAX Post From Button Click On Custom MVC Widget Returns 404

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. Kevin
    Kevin avatar
    9 posts
    Registered:
    27 Oct 2014
    17 Jun 2015
    Link to this post

    I have a custom MVC Widget contained in an external class assembly that returns a 404 error when a button click calls an ajax post function calling a method in the controller.

    The initial call to Index works, I have no custom routing set up.

    The button click calls a javascript function: 

         function saveRequest() {

            //create object
            var obj = {
                FirstName: $("#firstname").val()
                ,LastName: $("#lastname").val()
                , Email: $("#email").val()
                , UserName: $("#email").val()
                , Password: $("#password").val()
                , IsApproved: false
            };

            //pass it to controller
            $.ajax({
                type: "POST",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                url: "accountrequestwidget/saverequest",
                data: JSON.stringify({ request: obj }),
                success: function (response) {
                    ...
                },
                error: function (response) {
                   ...
                }
            }).done(function () {
                 ...
            });
        }

    And that calls this controller method:

            public virtual JsonResult SaveRequest(AccountRequestWidgetModel request)
            {
                 ...
                 return Json(new { status = "success", msg = "Request Successfully Sent" });
            }

    In the browser- I can directly type in the /page-name/method (localhost/sitefinitywebapp/account-request/saverequest) and get the method to run-  but putting that into the ajax url (e.g. page name/method)  still returns a 404.

     How do I make Ajax calls to the custom widget's controller methods?

     Thank you!
    Kevin Howell

  2. Alan
    Alan avatar
    3 posts
    Registered:
    24 Sep 2015
    31 Jan 2016 in reply to Kevin
    Link to this post

    Dude, can you fix this?

    I have the same error.

     

    Regards

2 posts, 0 answered