1
如何在View中編寫代碼以便訪問linq中的groupby字段。這裏的數據通過Web服務呈現。從控制器訪問組中的字段到MVC中的視圖3
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Find Member";
var obj = new SearchMemberServiceClient();
List<MemberProxy> members = obj.FindMember("Mason", "Birkes", "", "", "", "").Members;
var sorted = from a in members
orderby a.FirstName ascending
group a by new { a.FormattedFullName, a.PersonId, a.Associations, a.MembershipsProxy[0].MembershipId } into k
select new { formattedname = k.Key.FormattedFullName, id = k.Key.PersonId, assoc = k.Key.Associations, memprox = k.Key.MembershipId };
return View(sorted.ToList());
}
}
非常感謝你的詳細解釋。我現在能夠理解流程。 – Krishh 2011-12-21 17:25:00