Error executing template "/Designs/Kwpn/Paragraph/NewsList.cshtml" System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. at System.ThrowHelper.ThrowKeyNotFoundException() at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at Kwpn.Core.Services.NewsService.GetSelectedSubheader(IEnumerable`1 categories, IEnumerable`1 regions) in D:\a\1\s\Kwpn.Core\Services\NewsService.cs:line 271 at CompiledRazorTemplates.Dynamic.RazorEngine_f9fb26aeb4584e7fa7fb97405f8d7ef6.Execute() in D:\inetpub\wwwroot\www.kwpn.nl\Files\Templates\Designs\Kwpn\Paragraph\NewsList.cshtml:line 44 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 2 @using Kwpn.Core.Services.Abstract; 3 @using System.Web.Mvc; 4 @using System.Globalization; 5 @using Kwpn.Repository.Helpers; 6 @using Kwpn.Models.Viewmodels; 7 @using Kwpn.Repository; 8 @using Kwpn.Repository.Extensions; 9 @using Kwpn.Models.Constants; 10 11 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 12 13 14 @{ 15 var culture = GetGlobalValue("Global:Area.LongLang"); 16 var pageId = AreaHelper.GetAreaItemStringValueBySystemName(StringConstants.PageIdSystemNames.NewsPageId); 17 int amount = 25; 18 19 //only show newslist when no detail has been selected, detail output uses old querypublisher template 20 bool hasNewsItemId = System.Web.HttpContext.Current.Request.QueryString.AllKeys.Where(iid => iid != null).Select(iid => iid.ToLowerInvariant())?.Contains("itemid") ?? false; 21 if (!hasNewsItemId) 22 { 23 INewsService newsService = DependencyResolver.Current.GetService<INewsService>(); 24 IImageService imageService = DependencyResolver.Current.GetService<IImageService>(); 25 26 CultureInfo cultureInfo = new CultureInfo(culture); 27 var newsPageId = AreaHelper.GetAreaItemStringValueBySystemName(Kwpn.Models.Constants.StringConstants.PageIdSystemNames.NewsPageId); 28 var newsItems = newsService.GetNewsWithFilters(amount, 0, newsService.DateFrom, newsService.DateTo, culture, pageId, newsService.Categories, newsService.Regions, newsService.SelectedNews); 29 30 <div class="break-grid content-container page-content-aside news-list"> 31 <div class="break-grid-background"> 32 <div class="in-grid"> 33 <div class="row"> 34 <div class="background-head-aside-xs"> 35 <div class="background-head-aside-xs contentFilterHolder @(newsService.SelectedNews ? "selected" : "")"> 36 @if (newsService.SelectedNews) 37 { 38 <div class="col-xs-12 col-md-4 pull-right"> 39 <a class="orange_arrow_link pull-right" href="/Default.aspx?ID=@newsPageId">@Translate("MoreNews", "More news")</a> 40 </div> 41 <div class="col-md-8 title"> 42 <h2>@Translate("newsService.SelectedNews", "Selected news")</h2> 43 <div class="selectedNewsSettings"> 44 @foreach (var subheaderItem in newsService.GetSelectedSubheader(newsService.Categories, newsService.Regions)) 45 { 46 <span>@String.Format("{0}: <span class=\"item\">{1}</span>", TranslationHelper.Translate(subheaderItem.Key, culture), string.Join("</span><span class=\"item\">", subheaderItem.Value))</span> 47 <br /> 48 if (subheaderItem.Value.Count > 10) 49 {<br />} 50 } 51 </div> 52 </div> 53 } 54 else 55 { 56 <div class="col-md-12 page-header title"> 57 <h2> 58 @Translate("NewsForYou", "News for") 59 @if (culture.Equals("nl-NL", StringComparison.InvariantCultureIgnoreCase)) 60 { 61 <a class="content-filter-activator"> 62 @Translate("You", "you") <i class="fa fa-chevron-down hidden-xs hidden-sm"></i> 63 </a> 64 } 65 </h2> 66 </div> 67 <div class="row"> 68 <div class="col-xs-12 filter"></div> 69 </div> 70 } 71 </div> 72 @if (newsItems != null && newsItems.Any()) 73 { 74 // show highlighted items 75 <div class="row news-highlight-row"> 76 @foreach (var (highlightedItem, index) in newsItems.Take(2).WithIndex()) 77 { 78 string hightlightImage = highlightedItem.Image; 79 if (string.IsNullOrEmpty(hightlightImage)) 80 { 81 var highlightCategory = ""; 82 if (highlightedItem.Categories.Count > 0) 83 { 84 highlightCategory = highlightedItem.Categories[0].Trim(); 85 } 86 hightlightImage = imageService.GetDefaultImageByCategory(Kwpn.Models.Enumerations.ImageType.NewsCategoryImage, highlightCategory); 87 } 88 89 <a href="@($"/Default.aspx?ID={newsService.PageID}&itemId={StringConstants.ItemTypes.News}:{highlightedItem.Id}")"> 90 <div class="col-xs-12 @(index > 0 ? "col-md-5" : "col-md-7") news-highlight"> 91 <div class="news-highlight-image" style="background-image: url('@imageService.Optimize(hightlightImage, 1080, 720)')"> 92 <div class="news-highlight-mask"> 93 <div class="news-highlight-content-valigner"> 94 <div class="news-highlight-content"> 95 96 @if (!string.IsNullOrEmpty(highlightedItem.HighlightText)) 97 { 98 <div class='highlight'>@highlightedItem.HighlightText</div> 99 } 100 101 @if (!string.IsNullOrEmpty(highlightedItem.NoteText)) 102 { 103 <div class='note'>@highlightedItem.NoteText</div> 104 } 105 106 <span class="date">@FormatHelpers.GetDateTime(highlightedItem.NewsDate, null, cultureInfo, Translate("EventDateDevider", "to"))</span> 107 <span class="title">@highlightedItem.Title</span> 108 <span class="shortdescription">@highlightedItem.ShortDescription</span> 109 </div> 110 </div> 111 </div> 112 </div> 113 </div> 114 </a> 115 } 116 117 <div class="col-xs-12"> 118 <!-- /204473129/NieuwsOverzicht/Banner1 --> 119 <div id='div-gpt-ad-banner1-1' class="google-container google-container--size--a google-container--center google-container--margin-bottom"> 120 <script> 121 googletag.cmd.push(function () { googletag.display('div-gpt-ad-banner1-1'); }); 122 </script> 123 </div> 124 </div> 125 </div> 126 127 // remove highlighted items from list below 128 newsItems = newsItems.Except(newsItems.Take(2)).ToList(); 129 } 130 @if (!newsService.SelectedNews) 131 { 132 string postUrl = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(Convert.ToInt32(GetGlobalValue("Global:Page.ID"))); 133 <div class="background-aside-xs"> 134 135 <aside class="col-xs-12 col-md-4 col-md-push-8 news-list-filter"> 136 137 <div class="google-container google-container--size--b google-container--center google-container--margin-top google-container--margin-bottom"> 138 <!--onderstaande afbeelding moet worden verwijderd en vervangen worden door google admanager data--> 139 </div> 140 141 <div class="page-aside"> 142 <form name="KwpnNewsFilter" id="KwpnNewsFilter" method="POST" action='@postUrl'> 143 @{ 144 List<Kwpn_KwpnEventCategories> kwpnNewsCategories = KwpnEventHelper.GetEventCategories(GetGlobalValue("Global:Area.LongLang")); // uses event categories for now 145 if (kwpnNewsCategories != null && kwpnNewsCategories.Count > 0) 146 { 147 <h2 id="categories-aside-title" data-childId="categories-aside-content" class="notactive"><span>@Translate("Category", "Category")</span></h2> 148 <div id="categories-aside-content" class="aside-content notactive"> 149 @foreach (Kwpn.Repository.Kwpn_KwpnEventCategories category in kwpnNewsCategories) 150 { 151 <div class="checkbox"> 152 <label> 153 <input type="checkbox" name="category" id='@category.Value.JsEncode()' value='@category.Value.JsEncode()' @if (newsService.Categories.Contains(category.Value)) { <text> checked="checked" </text> }>@category.Label 154 </label> 155 </div> 156 } 157 </div> 158 } 159 } 160 <h2 id="period-aside-title" data-childId="period-aside-content" class="notactive"><span>@Translate("Period", "Period")</span></h2> 161 <div id="period-aside-content" class="aside-content notactive"> 162 <div class="form-group"> 163 <div class="input-group date"> 164 <input type="text" class="form-control" name="newsfrom" id="newsfrom" placeholder='@Translate("StartDate", "Start date")' value='@newsService.DateFrom' /> 165 </div> 166 </div> 167 <div class="form-group"> 168 <div class="input-group date"> 169 <input type="text" class="form-control" name="newsto" id="newsto" placeholder='@Translate("EndDate", "End date")' value='@newsService.DateTo' /> 170 </div> 171 </div> 172 </div> 173 <input type="submit" class="hidden" value="filter" id="submitfilter" /> 174 </form> 175 </div> 176 177 </aside> 178 </div> 179 } 180 </div> 181 182 <article class="col-xs-12 col-md-7 @(!newsService.SelectedNews ? "col-md-pull-4" : "") page-content news-list-output" id="news-list-output"> 183 184 @if (newsItems != null && newsItems.Any()) 185 { 186 187 foreach (var (newsItem, index) in newsItems.WithIndex()) 188 { 189 <a href="@($"/Default.aspx?ID={newsService.PageID}&itemId={StringConstants.ItemTypes.News}:{newsItem.Id}")"> 190 <div class='news-list-row mod-@(index % 2 == 0 ? "0" : "1")'> 191 <div class="row"> 192 <div class="col-xs-1 text-center"> 193 <i class="fa fa-clock-o"></i> 194 </div> 195 <div class="col-xs-10 date-time"> 196 @FormatHelpers.GetDateTime(newsItem.NewsDate, null, cultureInfo, Translate("EventDateDevider", "to")) 197 198 @if (!string.IsNullOrEmpty(newsItem.NoteText)) 199 { 200 <div class='note'>@newsItem.NoteText</div> 201 } 202 203 @KwpnNewsHelper.GetNewsRegion(string.Join(",", newsItem.Regions), culture, newsItem.NoteText) 204 </div> 205 206 @if (!string.IsNullOrEmpty(newsItem.HighlightText)) 207 { 208 <div class='highlight'>@newsItem.HighlightText</div> 209 } 210 211 </div> 212 <div class="row"> 213 <div class="col-xs-11 col-xs-offset-1"> 214 <h2>@newsItem.Title</h2> 215 @newsItem.ShortDescription 216 </div> 217 </div> 218 </div> 219 </a> 220 } 221 } 222 else 223 { 224 <p>@Translate("NoKwpnNewsItemsFound", "No news found.")</p> 225 } 226 </article> 227 </div> 228 <i id="news-list-output-spinner" class="fa waitingSpinner fa-spinner fa-spin fa-2x fa-fw margin-bottom hide"></i> 229 </div> 230 </div> 231 </div> 232 233 @SnippetStart("JavascriptsBottom") 234 <script> 235 $(function () { 236 // set local storage value for related news function 237 localStorage.setItem('news-categoryselection', '@string.Join(",", newsService.Categories)'); 238 239 // from date 240 var from = $("#newsfrom").datepicker({ 241 minDate: null, 242 maxDate: 'today' // accept all dates until today 243 }); 244 from.on("change", function() { 245 submitFilter(); 246 }); 247 248 // to date 249 var to = $("#newsto").datepicker({ 250 minDate: null, 251 maxDate: 'today' // accept all dates until today 252 }); 253 to.on("change", function() { 254 submitFilter(); 255 }); 256 257 // date culture initialize 258 $.datepicker.setDefaults($.datepicker.regional["@GetGlobalValue("Global:Area.Lang")"]); 259 260 var categories = $("input[name=category]").change(function () { submitFilter(); }); 261 262 function submitFilter() { 263 $(".news-highlight-row").hide(); 264 $(".news-list-output").html("<i class='fa fa-refresh fa-spin fa-3x fa-fw'></i><span class='sr-only'>Loading...</span>"); 265 $("#KwpnNewsFilter").submit(); 266 } 267 268 $(window).scroll(function () { 269 let container = document.querySelector('#news-list-output'); 270 let lastArticle = document.querySelector('#news-list-output a:last-of-type'); 271 let containerOffset = document.documentElement.offsetTop - (container.offsetTop + container.offsetHeight); 272 273 let position = $(window).scrollTop(); 274 let target = Math.abs(containerOffset); 275 276 if (position > (target - lastArticle.offsetHeight) && !progressing) { 277 loadNewsArticles(); 278 } 279 }); 280 281 let fetched = []; 282 let progressing = false; 283 284 function loadNewsArticles(index) { 285 286 let culture = '@(culture)'; 287 let pageId = '@(pageId)'; 288 let skipAmount = getSkipAmount(); 289 let amount = 25; 290 let dateFrom = '@(newsService.DateFrom.ToShortDateString())'; 291 let dateTo = '@(newsService.DateTo.ToShortDateString())'; 292 let categories = '@(string.Join(",", newsService.Categories))'; 293 let regions = '@(string.Join(",", newsService.Regions))'; 294 let selectedNews = '@(newsService.SelectedNews)'; 295 296 spinner(true); 297 298 fetch(`/kwpnwebapi/news/getnewswithfilters/${amount}/${skipAmount}/${dateFrom}/${dateTo}/${culture}/${pageId}/${categories == '' ? 'none' : categories}/${regions == '' ? 'none' : regions}/${selectedNews}`) 299 .then(response => { 300 301 // Check if response status is 429 (Too Many Requests) 302 if (response.status === 429) { 303 loadNewsArticles(index); 304 } 305 306 // Process the response if successful 307 return response.json(); 308 }) 309 .then(data => { 310 311 const container = document.querySelector('#news-list-output'); 312 const options = { day: 'numeric', month: 'long', year: 'numeric' }; 313 314 data.forEach(article => { 315 316 if (!fetched.includes(article.Id)) { 317 fetched.push(article.Id); 318 319 let newsDate = new Date(article.NewsDate); 320 321 container.insertAdjacentHTML('beforeend', ` 322 <a href="/nieuws?itemId=NewsItem:${article.Id}" id="news-list-article-${article.Id}"> 323 <div class="news-list-row mod-1"> 324 <div class="row"> 325 <div class="col-xs-1 text-center"> 326 <i class="fa fa-clock-o"></i> 327 </div> 328 <div class="col-xs-10 date-time"> 329 ${newsDate.toLocaleDateString('@(culture)', options)} | ${(newsDate.getHours() < 10 ? "0" + newsDate.getHours() : newsDate.getHours())}:${(newsDate.getMinutes() < 10 ? "0" + newsDate.getMinutes() : newsDate.getMinutes())} 330 ${article.RegionLabel} 331 </div> 332 </div> 333 <div class="row"> 334 <div class="col-xs-11 col-xs-offset-1"> 335 <h2>${article.Title}</h2> 336 ${article.ShortDescription} 337 </div></div></div> 338 </a> 339 `); 340 341 scrollToId(`news-list-article-${data[0].Id}`); 342 } 343 }); 344 345 if (data.length === 0) { 346 deLoadNewsArticles(); 347 } 348 }) 349 .catch(error => console.error(error)); 350 } 351 352 function scrollToId(id) { 353 document.getElementById(id).scrollIntoView(); 354 spinner(false); 355 } 356 357 function spinner(enabled) 358 { 359 if(enabled === true) 360 { 361 document.getElementById("news-list-output-spinner").classList.remove("hide"); 362 } else { 363 document.getElementById("news-list-output-spinner").classList.add("hide"); 364 } 365 366 progressing = enabled; 367 } 368 369 function getSkipAmount() 370 { 371 if(fetched.length === 0) 372 { 373 return parseInt('@(amount)'); 374 } 375 376 return fetched.length + parseInt('@(amount)'); 377 } 378 379 function deLoadNewsArticles() { 380 spinner(false); 381 loadNewsArticles = function () { console.log('No more news to fetch.') }; 382 } 383 }); 384 385 386 </script> 387 @SnippetEnd("JavascriptsBottom") 388 389 } 390 } 391
The KWPN (Studbook of the Royal Dutch Sport Horse) is a Netherlands-based organization specializing in the breeding of jumpers, dressage horses, harness horses, and Gelder horses.
More info