复杂的WebGrid在MVC 3绑定 [英] Complex WebGrid Binding in MVC 3
本文介绍了复杂的WebGrid在MVC 3绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们说我有这样的父对象(伪code)
Let's say I have a Parent object like this (in pseudo code)
public Parent()
string FirstName
string LastName
IEnumarable<Child> Children
Child GetOldestChild() <- A function that returns the oldest child in Children
public Child()
string ChildFirstName
string ChildLastName
int ChildAge
好了,我想绑定的WebGrid的IEnumarable&LT;家长>,每一行我想要显示的父姓和名,最大的孩子的名字/姓氏/年龄
Ok, so I want to bind a WebGrid an IEnumarable< Parent >, and in each row I want to display the first and last name of the parent, and the firstname/lastname/age of the oldest child.
获取父列很容易,我可以绑定是这样的:
Getting the parent columns is easy, I can just bind like this:
grid.Column("FirstName")
但是,让老大的数据是什么,我不知道该怎么办。这并不工作,但它是我想要完成的任务:
But getting the oldest child data is what I don't know how to do. This doesn't work, but it's what I want to accomplish:
grid.Column("GetOldestChild().ChildFirstName")
希望我失去了一些东西简单...
Hopefully I'm missing something simple...
推荐答案
试试这个方法:
public Parent()
string FirstName
string LastName
IEnumarable<Child> Children
private Child GetOldestChild()
public Child OldestChild { get { return GetOldestChild() } };
public Child()
string ChildFirstName
string ChildLastName
int ChildAge
grid.Column("OldestChild.ChildFirstName")
这篇关于复杂的WebGrid在MVC 3绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文