-1

Newtonsoft.Jsonを使用してredisキャッシュから文字列を逆シリアル化しようとすると、このエラーが発生します。 JsonConvert.DeserializeObject<HeaderTopViewComponent>(cacheValue.Result.ToString());Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.DynamicViewDataタイプに使用するデフォルトのコンストラクタを見つけることができません

タイプMicrosoft.AspNetCore.Mvc.ViewFeatures.Internal.DynamicViewDataに使用するデフォルトコンストラクタが見つかりません:HeaderTopViewComponentのような私のビューコンポーネント「」

の一つのモデルクラスである

。パス「ViewBag」、行1、位置340

出力文字列:私は私のviewcomponentモーダルクラスにいくつかのタグを追加することによって、それを修正し、

[JsonObject(MemberSerialization.OptIn)][JsonProperty]のような設定プロパティを取得している

{"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

//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] 

そして今、その作業

関連する問題