I'm using Umbraco CMS. I have the following model:
public class LoyaltyPromo : RenderModel
{
public LoyaltyPromo(IPublishedContent content)
: base(content)
{
}
//properties removed for brevity
}
I want to use this model inside UmbracoApiController
. So i do this:
public class PromoServiceController : UmbracoApiController
{
public async Task<object> GetAll()
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
IPublishedContent content = umbracoHelper.TypedContent(1050);
var list = new List<LoyaltyPromo>();
list.Add(new LoyaltyPromo(content));
return list;
}
}
Unfortunately it doesn't work, i get the NullReferenceException
:
An error has occurred. Object reference not set to an instance of an object. System.NullReferenceException at Umbraco.Web.Models.RenderModel..ctor(IPublishedContent content) at LoyaltyOps.Models.LoyaltyPromo..ctor(IPublishedContent content) in C:\Users\mkallingal\documents\visual studio 2015\Projects\LoyaltyOps\LoyaltyOps.Models\LoyaltyPromo.cs:line 13 at LoyaltyOps.Controllers.PromoServiceController.d__0.MoveNext() in C:\Users\mkallingal\documents\visual studio 2015\Projects\LoyaltyOps\LoyaltyOps\Controllers\PromoServiceController.cs:line 32 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Threading.Tasks.TaskHelpersExtensions.d__3`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()
How can i resolve this?
public LoyaltyPromo(IPublishedContent content) : base(content) { }
– IrshuContent
->Promos-List
(content name) -> Id (from theProperties
tab) .IPublishedContent content = umbracoHelper.TypedContent(1050);
returns all the info of the content; it's not null. – Irshu