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}
カスタム型コンバータを記述しないかぎり、デフォルトのコンストラクタを持たないオブジェクトに逆シリアル化することはできません。 –