0

共有エディターテンプレートを使用して、次のような「EditorFor」HTMLヘルパーを使用してビューにネストされたコレクションをレンダリングしています。私はこれらのネストされた部分ビューのすべてが好きではありませんが、この方法で要素に適切な名前を付けて、問題なくViewModelのコントローラーにポストバックできるようにします。

ネストの最も断固としたレベルで順序を並べ替えるにはどうすればよいですか?この場合、「Budget.vbhtml」を年順(降順)で表示するにはどうすればよいですか?

前もって感謝します!

トップレベルビュー(Organization.vbhtml):

<div id="budgets">
     @Html.EditorFor(Function(org) org.OrganizationBudgets))
</div>

OrganizationBudget.vbhtml:

@ModelType CharityMVC.OrganizationBudget
@Html.EditorFor(Function(ob) ob.Budget)

Budget.vbhtml:

@ModelType CharityMVC.Budget
@Model.Year @Html.EditorFor(Function(b) b.Amount)

アップデート:

Modelオブジェクトにデータを入力するときに、コントローラーでこれを行う必要があるようですが、linqクエリで子または子の子を並べ替えるにはどうすればよいですか?これは私の現在のコードです:

Function Edit(ByVal id As Integer) As ActionResult
    Dim o As Organization
    Dim ovm As OrganizationViewModel

    'Load the organization from the database
    o = (From org In _db.Organizations _
        Where org.Id = id _
        Select org).FirstOrDefault()

    'Map it to the ViewModel
    ovm = AutoMapper.Mapper.Map(Of Organization, OrganizationViewModel)(o)

    Return View(ovm)

End Function
4

1 に答える 1

0

これまでの私のベストアンサー:

次のように子プロパティを設定する複数のLINQクエリ:

Function Edit(ByVal id As Integer) As ActionResult
    Dim o As Organization
    Dim ovm As OrganizationViewModel

    'Load the organization from the database
    o = (From org In _db.Organizations _
        Where org.Id = id _
        Select org).FirstOrDefault()

    o.OrganizationBudgets = (From ob In _db.OrganizationBudgets _
                             Where ob.OrganizationId = o.Id _
                             Order By ob.Budget.Year Descending _
                             Select ob).ToList()


    'Map it to the ViewModel
    ovm = AutoMapper.Mapper.Map(Of Organization, OrganizationViewModel)(o)

    Return View(ovm)

End Function
于 2011-05-26T20:03:27.597 に答える