-1

Я получаю эту ошибку при попытке десериализовать строку из кеша redis с помощью Newtonsoft.Json.Невозможно найти конструктор по умолчанию для типа Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.DynamicViewData

где HeaderTopViewComponent является модель класса одного моего вида компонента «»

как: JsonConvert.DeserializeObject<HeaderTopViewComponent>(cacheValue.Result.ToString());

Невозможно найти конструктор по умолчанию, используемый для типа Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.DynamicViewData. Путь 'ViewBag', строка 1, позиция 340.

Выходная строка:

{"ShowTopheaderSection":true,"PageHeader":"MSHSL","FriendlyURL":"/MSHSL","leagueList":[{"leagueId":0,"FriendlyURL":"/","leaguename":"--Select--"},{"leagueId":3,"FriendlyURL":"/MSHSL","leaguename":"MSHSL"},{"leagueId":4,"FriendlyURL":"/CHSAA","leaguename":"CHSAA"}],"HttpContext":null,"Request":null,"User":null,"RouteData":null,"ViewBag":{},"ModelState":{},"Url":null,"ViewComponentContext":{"Arguments":null,"HtmlEncoder":null,"ViewComponentDescriptor":{"DisplayName":null,"FullName":null,"Id":"9882d08a-1c50-4c59-8a30-2d9c843957e9","ShortName":null,"TypeInfo":null,"MethodInfo":null},"ViewContext":{"FormContext":null,"ClientValidationEnabled":false,"Html5DateRenderingMode":0,"ValidationSummaryMessageElement":null,"ValidationMessageElement":null,"ViewBag":{},"View":null,"ViewData":{},"TempData":null,"Writer":null,"ExecutingFilePath":null,"ActionDescriptor":null,"HttpContext":null,"ModelState":{},"RouteData":null},"ViewData":{},"Writer":null},"ViewContext":{"FormContext":null,"ClientValidationEnabled":false,"Html5DateRenderingMode":0,"ValidationSummaryMessageElement":null,"ValidationMessageElement":null,"ViewBag":{},"View":null,"ViewData":{},"TempData":null,"Writer":null,"ExecutingFilePath":null,"ActionDescriptor":null,"HttpContext":null,"ModelState":{},"RouteData":null},"ViewData":{},"ViewEngine":null} 
+1

Вы не можете десериализовать объекты, у которых нет конструктора по умолчанию, если вы не напишите конвертер пользовательского типа. –

ответ

0

У меня есть это исправить, добавив некоторые тег в моем классе viewcomponent модальной и получить набор свойство как

[JsonObject(MemberSerialization.OptIn)] и [JsonProperty]

//Tag to add only selected property when Deserialize or Serialize using Newtonsoft 
    [JsonObject(MemberSerialization.OptIn)] 
    public class HeaderTopViewComponent:ViewComponent 
    { 
     #region //Property// 
     [JsonProperty] 
     public bool ShowTopheaderSection { get; set; } 
     [JsonProperty] 
     public string PageHeader { get; set; } 
     [JsonProperty] 
     public string FriendlyURL { get; set; } 
     [JsonProperty] 

И теперь его работы

Смежные вопросы