您必须遵循以下步骤;1)在模型中创建返回值类:
public class ClassResult
{
public int a1 { get; set; }
public int b1 { get; set; }
}
然后在控制器上
编写查询如下:
public ActionResult Index()
{
List<TableAClass> ListA = new List<TableAClass>();
List<TableBClass> ListB = new List<TableBClass>();
List<TableCClass> ListC = new List<TableCClass>();
List<ClassResult> res = new List<ClassResult>();
res = (from p1 in ListA join p2 in ListB on p1.a1 equals p2.b1 select new ClassResult { a1=p1.a1 ,b1=p2.b1 }).ToList();
return View(res);
}
3) 在视图上,
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.ClassResult>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Index1</title>
</head>
<body>
<fieldset>
<legend>Fields</legend>
<div class="display-label">a1</div>
<div class="display-field"><%: Model.a1 %></div>
<div class="display-label">b1</div>
<div class="display-field"><%: Model.b1 %></div>
</fieldset>
</body>
</html>