3

部分ビューで 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

4

2 に答える 2

1

試す[ScriptIgnore(ApplyToOverrides = true)]

于 2014-07-14T10:36:34.967 に答える
0

すべての仮想プロパティに対してScriptIgnore、次のように属性を使用する必要があります。[ScriptIgnore(ApplyToOverrides = true)]

于 2015-09-17T17:01:37.200 に答える