部分ビューで ScriptIgnore タグを使用してプロパティのシリアル化を停止するのに問題があります。
var docs = @Html.Raw(Json.Encode(モデル))
面白いことに、.tt ファイルの部分クラスに属性を直接追加すると期待どおりに動作するのですが、code-gen を実行するとそのファイルが上書きされるため、MetadataType を使用してみました
[MetadataType(typeof(DocumentMeta))] //this is added so we can add meta data to our partial class..
public partial class Document
{
}
[MetadataType(typeof(DocumentCategoryMeta))] //this is added so we can add meta data to our partial class..
public partial class DocumentCategory
{
}
public class DocumentMeta
{
[ScriptIgnore] //We add the scriptignore here because we are serializing some of these entities in client code
public virtual ICollection<DocumentCategory> DocumentCategories { get; set; }
}
public class DocumentCategoryMeta
{
[ScriptIgnore] //We add the scriptignore here because we are serializing some of these entities in client code
public virtual DocumentCategory Parent { get; set; }
}
「DocumentCategory」タイプのオブジェクトをシリアライズ中に循環参照が検出されました。
DocumentCategory には階層データが含まれているためです。
どんな助けでも大歓迎です!
トライブ84