How to create an instance of a model that inherits RenderModel inside UmbracoApiController?
Hello Umbraco, I have the following model:
public class LoyaltyPromo : RenderModel
{
public LoyaltyPromo(IPublishedContent content)
: base(content) // the error points here
{
}
//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));
}
}
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.d0.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.d3`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.d0.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.d2.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 to create an instance of a model that inherits RenderModel inside UmbracoApiController?
Hello Umbraco, I have the following model:
I want to use this model inside UmbracoApiController. So i do this:
Unfortunately it doesn't work, i get the
NullReferenceException
:How can i resolve this?
whats on line 13 of LoyaltyPromo?
this is where the error pointing to (line 13)
Hi, Here is the screenshot where i'm getting the exception. Any help or hint is much appreciated.
Why are you using the rendermodel? The renderModel is normally used in the RenderMvcController
I would create my own model, or use the modelsBuilder class.
is working on a reply...