0

I am trying to make an SXA component in which I can take a users cookie preferences, when the submit button is clicked the details from the form will be saved in a cookie so that the management of the cookies can be manager through Google Tag Manager.

I am currently struggling with some basic form stuff, I keep recieving the error listed below this section.

View: https://hatebin.com/lioisieknu

Controller: https://hatebin.com/deigokdoaf

NOTE: I notice that when I was previously using Index, and then Index with a [HttpPost] on top, when I loaded the component it would immediately call the [HttpPost] item, and ignore the initial "Index" ActionResult. I checked in Chrome dev tools, and the module was coming through as a POST, I don't know if this is relevant, but worth mentioning I thought.

Attempt to retrieve context object of type 'Sitecore.Mvc.Presentation.RenderingContext' from empty stack.

Stack Trace:

[InvalidOperationException: Attempt to retrieve context object of type 'Sitecore.Mvc.Presentation.RenderingContext' from empty stack.]
   Sitecore.Mvc.Common.ContextService.Peek() +259
   Company.Sc.Feature.CookieManagement.Controllers.CookieController.CookiePreferences(CookieViewModel model) in C:\Users\jackhayward\Source\Repos\GDPR\GDPR\src\Feature\CookieManagement\code\Controllers\CookieController.cs:29
   lambda_method(Closure , ControllerBase , Object[] ) +139
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
   System.Web.Mvc.c__DisplayClass24_0.b__0() +80
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +454
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +454
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +524
  • 1
    The issue is with post method, at that time you will not get the datasource item: "var datasource = Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.Item". At the time of loading the view pass datasource item id to view via model and while submitting access that model in post method to get the datasource item id and use it. To pass the Datasource item id to model, you have to add new attribute in your model class CookieViewModel and access the same attribute in Post method. – Amit Kumar Feb 22 '19 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.