Copied to clipboard

Flag this post as spam?

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


  • Keith Bamberger 26 posts 106 karma points
    Sep 24, 2014 @ 23:17
    Keith Bamberger
    0

    Using Ajax to call surfacecontroller and return View/PartialView

    Hi all, 

    Im using Umbraco 7.1.6 and have set up a controller + model and am successfully rendering views / partialviews, but i have stumbled across a problem now, that ive spent a while trying to get past with no luck.

    My error occurs on (public RaknaTeckna() : this(new UmbracoHelper(UmbracoContext.Current).TypedContent(UmbracoContext.Current.PageId)) { }) UmbracoContext is null.

    public class RaknaTeckna : RenderModel
    {
            public string somethings { get; set; }

            public RaknaTeckna() : this(new UmbracoHelper(UmbracoContext.Current).TypedContent(UmbracoContext.Current.PageId)) { }
            public RaknaTeckna(IPublishedContent content, CultureInfo culture) : base(content, culture) { }
            public RaknaTeckna(IPublishedContent content) : base(content) { }
    }

    Im calling my controller from an ajax call (see below, have changed out the data im sending in). I get into my controller just fine and the objects i send in with the data also arrives, but because im calling the controller directly the UmbracoContext is null. 
    $.ajax({

                cache: false,
                type: "POST",
                url: '/umbraco/surface/mycontroller/myaction/',

                data: { "somethings": somethings },

                success: function (data)
                {
                    $("#boxes").html('');
                    $("boxes").html(data);
                },

                error: function (xhr, ajaxOptions, thrownError)
                {
                    console.log(xhr);
                    $("#calculateerror").html(xhr);
                 }
             });    

    How can i fill the UmbracoContext if coming to the controller from ajax? 

    /Keith

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft