登録したばかりですが、これが初めての投稿ですので、質問が良くない場合はご容赦ください。私は調べてみましたが、私の要件に合った答えを見つけることができません。これはおそらく、私が望むことを達成することができないためです。
ビューモデルからEditorForフィールドのIEnumerableリストを取得する部分ビューがあります。
@model DocumentViewModelContainer
@Html.EditorFor(m => m.Document.Metadata)
DocumentViewModelContainerのコードは次のとおりです。
public class DocumentViewModelContainer
{
public DocumentViewModel Document
{
get;
set;
}
DocumentViewModelのコードは次のとおりです。
public class DocumentViewModel
{
public IEnumerable<DocumentMetadataFieldViewModel> Metadata
{
get;
set;
}
}
両方のビューモデルには、この質問とは無関係であるとして除外したオブジェクトが他にもたくさんあります。DocumentMetadataFieldViewModelは、標準タイプ(int、stringsなど)のいくつかのフィールドで構成されています。
私が達成しようとしているのは、次のように、ボトムビューモデルのオブジェクトによる順序付けによってプルバックされたこのリストにOrderByを追加することです。
@model DocumentViewModelContainer
@Html.EditorFor(m => m.Document.Metadata.OrderBy(i => i.InstanceFieldOrder))
ただし、これによりエラーが発生します。
System.InvalidOperationException : Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
私はMVCだけでなく、C#全般にも慣れていません。このプロジェクトは私にその場で言語を学ばせてくれたので、素敵に遊んでください:)
ありがとう、
マーク