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({
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
is working on a reply...