0

我正在使用共享编辑器模板通过“EditorFor”HTML 帮助程序在我的视图中呈现嵌套集合,类似于以下内容。我不喜欢所有这些嵌套的局部视图,但这样做会适当地命名元素,以便它们在 ViewModel 中回发到我的控制器而不会出现问题。

我将如何在巢的最坚决级别对订单进行排序?在这种情况下,我将如何让“Budget.vbhtml”以年份顺序(降序)显示?

提前致谢!

顶级视图(Organization.vbhtml):

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

组织预算.vbhtml:

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

预算.vbhtml:

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

更新:

当我填充我的模型对象时,听起来我应该在我的控制器中执行此操作,但是如何在 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 回答