Yes there is, but not quite like that. The way to do what you wish to do is to create a custom ViewModel class. This class (MyPageViewModel) would have two (or more) properties, one for each of your objects. In your view, you would access them using Model.Table1Data
and Model.Table2Data
.
A custom ViewModel class is very simple:
public class MyPageViewModel
{
public IQueryable<Table1Data> Table1Data { get; set; }
public IQueryable<Table2Data> Table2Data { get; set; }
}
You view would need to be strongly typed to this custom ViewModel class.
<%@ Page Title="MyPage" MasterPageFile="~/Application/Master Pages/Site.Master"
Inherits="System.Web.Mvc.ViewPage(Of MyAppNamespace.MyPageViewModel)" %>
Don't try to type that youself; easier to create a new view and check "strongly typed" view, and specify your New Custom Viewmodel class.
Then your action Controller method would be:
public class HomeController : Controller
{
public ActionResult Index()
{
MyDataContext dc = new MyDataContext();
MyPageViewModel vm = new MyPageViewModel();
vm.Table1Data = from n in dc.Table1
select n;
vm.Table1Data = from k in dc.Table2
select k;
return View(vm);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…