Copied to clipboard

Flag this post as spam?

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


  • Akeem 43 posts 198 karma points
    Mar 22, 2016 @ 18:00
    Akeem
    0

    Umbraco Ajax load more onclick of a button using surfacecontroller

    Please can anyone help me . I am trying to use Ajax for to load more calendar event thats coming from my umbraco backend . from this code below

    enter image description here

    [HttpPost]
    public ActionResult LoadEvent(int number)
    {
        var model = Umbraco.Content(1121).eventDetails;
    
        return model;
    }
    

    My SmartController is located inside App_Code folder . Below is the Ajax am working on

    $(document).ready(function (e) {
    
    $(".buttonListener").click(function () {
    
            //  e.preventDefault();
            $.ajax(
            {
    
                url: "/SmartController/SmartSurface",        //"/SmartCalendar",
                data : {number: 1},
                success: function (data) {
                    alert(data);
                },
                error: function () {
                    alert("Ka pow!");
                }
            });
            return true;
    });
    

    });

    Please help me somebody ....

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Mar 23, 2016 @ 07:28
    Dennis Adolfi
    0

    Hi Akeem. I would probobly prefer to return a ViewModel as JsonResult to my view. Looking your above ActionResult, it looks like you are returning the complete dynamic model to the view. It´s probobly better to return a viewmodel with the properties that you want to use in the front end.

    Se my response to this question for a working ajax example: https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/75559-pulling-child-node-content-via-ajax-or-some-other-method

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Mar 23, 2016 @ 07:47
    Dave Woestenborghs
    0

    Hi Akeem,

    Can you post the entire code of your controller ? If it's a surface controller and the name is SmartSurfaceController then the url should be :

    /umbraco/SmartSurface/LoadEvent

    Have a look at the documentation of Surface controllers and especially the part about routing :

    https://our.umbraco.org/documentation/Reference/Routing/surface-controllers

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft