Error executing template "Designs/Leander/_parsed/Index-b2c.parsed.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_3186f12886fc4870bd2afaf9d40c1ac2.Execute() in D:\dynamicweb.net\Solutions\leander.cloud-dynamicweb-cms.com\Files\Templates\Designs\Leander\_parsed\Index-b2c.parsed.cshtml:line 95
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel> 2 3 @Title("General page template") 4 @Description("General template for pages") 5 6 @using System.Web.Mvc; 7 @using Leander.Models; 8 @using Namotion.Reflection 9 @using Newtonsoft.Json; 10 11 @{ 12 var pageId = Model.ID; 13 14 var dwRequest = Dynamicweb.Context.Current.Request; 15 16 var _generalHelper = new Leander.Helpers.GeneralHelper(); 17 18 var redirectUrl = _generalHelper.GetRedirectionUrl(dwRequest?.RawUrl?.ToLower(), Model.Area.ID); 19 20 var contentType = Dynamicweb.Context.Current.Request.Headers.GetValues("Content-Type")?.FirstOrDefault(); 21 22 if (!string.IsNullOrWhiteSpace(redirectUrl) && contentType == null) 23 { 24 Dynamicweb.Context.Current.Response.Redirect(redirectUrl, true); 25 } 26 27 var _groupSerivce = new Leander.Services.GroupService(); 28 var _productService = new Leander.Services.ProductService(); 29 var _breadcrumbService = new Leander.Services.BreadcrumbService(); 30 var _userService = new Leander.Services.UserService(); 31 var _pageService = new Leander.Services.PageService(); 32 var token = ""; 33 var _isProduction = Dynamicweb.Configuration.SystemConfiguration.Instance.GetValue("/GlobalSettings/PicoPublishSettings/IsProduction")?.ToLower() == "true"; 34 35 var languages = new Dynamicweb.Ecommerce.International.LanguageService().GetLanguages(); 36 37 contentType = !string.IsNullOrWhiteSpace(contentType) ? contentType : !string.IsNullOrEmpty(dwRequest.QueryString["contenttype"]) ? dwRequest.QueryString["contenttype"] : "text/html"; 38 var renderAll = contentType == "text/html"; 39 40 // Check if parameters given to show settings, translations, navigation/menu and user 41 bool outputSettings = dwRequest.QueryString["settings"]?.ToString() == "1" || renderAll ? true : false; 42 bool outputTranslations = dwRequest.QueryString["translations"]?.ToString() == "1" || renderAll ? true : false; 43 bool outputMenu = dwRequest.QueryString["menu"]?.ToString() == "1" || renderAll ? true : false; 44 var languageId = languages.FirstOrDefault(x => x.Culture == Model.Languages?.FirstOrDefault(y => y.IsCurrent)?.Culture)?.LanguageId; 45 46 if (string.IsNullOrWhiteSpace(languageId)) 47 { 48 languageId = languages.FirstOrDefault(x => x.Culture == Model.Area.Languages?.FirstOrDefault(y => y.IsCurrent)?.Culture)?.LanguageId; 49 } 50 51 PageModel basePage = _pageService.GetPage(pageId, Model.Area.ID, languageId); 52 CategoryPageModel categoryPage = new CategoryPageModel(); 53 ProductPageModel productPage = new ProductPageModel(); 54 var pageJson = basePage; 55 56 basePage.Breadcrumbs = _breadcrumbService.GetBreadcrumbs(Model); 57 58 // Convert basepage to categorypage model 59 var json = JsonConvert.SerializeObject(basePage); 60 61 62 bool isCategoryPage = Model.ItemType == "CategoryPage" ? true : false; 63 bool isProductPage = Model.ItemType == "ProductPage" ? true : false; ; 64 65 if (Model.ItemType == "CategoryPage") 66 { 67 categoryPage = JsonConvert.DeserializeObject<CategoryPageModel>(json); 68 69 if (categoryPage != null) 70 { 71 var groupId = dwRequest.QueryString["GroupID"]; 72 if (!string.IsNullOrEmpty(groupId)) 73 { 74 Dynamicweb.Ecommerce.Products.Group group = new Dynamicweb.Ecommerce.Products.GroupService().GetGroup(groupId); 75 76 categoryPage.Category = _groupSerivce.GetLimitedGroupRelationModel(groupId, Model.Area.ID, languageId); 77 categoryPage.Products = _productService.GetProductList(groupId, Model.Area.ID, languageId, token, includeSubGroups: true); 78 79 categoryPage.Breadcrumbs = _breadcrumbService.GetBreadcrumbs(group, Model.Area, languageId); 80 categoryPage.B2CContent = _pageService.GetLandingPageContent(group, Model.Area.ID, languageId); 81 } 82 categoryPage.Alias = Model.ItemType; 83 } 84 85 pageJson = categoryPage; 86 } 87 if (Model.ItemType == "ProductPage") 88 { 89 productPage = JsonConvert.DeserializeObject<ProductPageModel>(json); 90 91 if (productPage != null && !string.IsNullOrWhiteSpace(Dynamicweb.Context.Current.Request["ProductID"])) 92 { 93 productPage.Product = _productService.GetProduct(Dynamicweb.Context.Current.Request["ProductID"], Model.Area.ID, languageId, token); 94 95 Dynamicweb.Ecommerce.Products.Product thisProduct = new Dynamicweb.Ecommerce.Products.ProductService().GetProductByNumber(productPage.Product.Number, "LANG1"); 96 97 productPage.Breadcrumbs = _breadcrumbService.GetBreadcrumbs(thisProduct, Model.Area, languageId); 98 } 99 100 pageJson = productPage; 101 } 102 103 104 var area = Model.Area; 105 106 // If page not found, just return 107 //if (page == null) { return; } 108 109 // TODO - Håndtering af forskellige side-itemtyper 110 111 var contentContainer = string.Empty; 112 var settingsJson = outputSettings == true ? new Leander.Services.SettingsService().GetSettings(Model.Area, languageId, pageId) : null; 113 var translationJson = outputTranslations == true ? new Leander.Services.TranslationService().GetTranslation(Model.Area) : null; 114 var menuJson = outputMenu == true ? new Leander.Services.MenuService().GetNavigationObject(Model) : null; 115 116 PageObjectModel pageObject = new PageObjectModel() 117 { 118 Page = pageJson, 119 Settings = settingsJson, 120 Translations = translationJson, 121 Menu = menuJson, 122 AreaId = Model.Area.ID.ToString(), 123 RedirectUrl = redirectUrl 124 }; 125 126 var finalJson = _generalHelper.JsonIndexSerialize(pageObject); 127 128 switch (Model.ItemType) 129 { 130 case "HomePage": 131 case "ContentPage": 132 contentContainer = finalJson; 133 break; 134 135 case "CategoryPage": 136 //dynamic moduleContent = Newtonsoft.Json.JsonConvert.DeserializeObject(Model.Content["DEFAULT"]); 137 138 //contentContainer = moduleContent; 139 contentContainer = finalJson; 140 141 break; 142 143 case "ProductPage": 144 contentContainer = finalJson; 145 146 break; 147 148 case "CartPage": 149 contentContainer = finalJson; 150 break; 151 152 default: 153 contentContainer = finalJson; 154 break; 155 } 156 157 Pageview.Page.ContentType = "text/html"; 158 159 if (basePage.Alias == "404Page") 160 { 161 Dynamicweb.Context.Current.Response.StatusCode = 404; 162 } 163 } 164 165 @if (contentType == "application/json") 166 { 167 @contentContainer 168 } 169 else 170 { 171 <html> 172 <head> 173 <meta charset="utf-8" /> 174 <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 175 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" /> 176 177 <title>@pageObject.Page.Title</title> 178 <meta name="description" content="@pageObject.Page.Description" /> 179 <meta name="og:title" content="@pageObject.Page.SchemaTitle" /> 180 <meta name="og:description" content="@pageObject.Page.SchemaDescription" /> 181 <meta name="og:image" content="@pageObject.Page.SchemaImage" /> 182 183 @if (!string.IsNullOrWhiteSpace(Model.MetaTags)) 184 { 185 @Model.MetaTags 186 } 187 188 <link rel="canonical" href="@pageObject.Page.Canonical" /> 189 190 <script defer="defer" src="@_generalHelper.RenderPath("main.js", true)"></script> 191 <link href="@_generalHelper.RenderPath("main.css", true)" rel="stylesheet"> 192 193 @if (_isProduction) 194 { 195 <!-- Google Tag Manager --> 196 <script> 197 (function (w, d, s, l, i) { 198 w[l] = w[l] || []; w[l].push({ 199 'gtm.start': 200 new Date().getTime(), event: 'gtm.js' 201 }); var f = d.getElementsByTagName(s)[0], 202 j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src = 203 'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f); 204 })(window, document, 'script', 'dataLayer', 'GTM-5T6WVLK');</script> 205 <!-- End Google Tag Manager --> 206 } 207 else{ 208 <!-- Google Tag Manager --> 209 <script> 210 (function (w, d, s, l, i) { 211 w[l] = w[l] || []; w[l].push({ 212 'gtm.start': 213 new Date().getTime(), event: 'gtm.js' 214 }); var f = d.getElementsByTagName(s)[0], 215 j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src = 216 'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f); 217 })(window, document, 'script', 'dataLayer', 'GTM-M5NSLCZH');</script> 218 <!-- End Google Tag Manager --> 219 } 220 221 </head> 222 <body> 223 224 @if (_isProduction) 225 { 226 <!-- Google Tag Manager (noscript) --> 227 <noscript> 228 <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5T6WVLK" 229 height="0" width="0" style="display:none;visibility:hidden"></iframe> 230 </noscript> 231 <!-- End Google Tag Manager (noscript) --> 232 } 233 else{ 234 <!-- Google Tag Manager (noscript) --> 235 <noscript> 236 <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M5NSLCZH" 237 height="0" width="0" style="display:none;visibility:hidden"></iframe> 238 </noscript> 239 <!-- End Google Tag Manager (noscript) --> 240 } 241 242 <div id="root"></div> 243 <script id="data-script"> 244 var pageContent = @contentContainer; 245 </script> 246 247 </body> 248 </html> 249 } 250