@using QunZhongLuXian.Models
@model List<……>
class AllModel
{
public 领导讲话的Model类型 Jianghua { get; set; }
public 工作动态的Model类型 Dongtai { get; set; }
}
如果不止一个讲话,可以包含 List<领导讲话的Model类型>
—-
—-
类中的Index()方法实例化并调用,传什么格式的参数到对应的View,本人菜鸟,麻烦详细一点啊
—-
model.Jianghua = db.xxxxx
model.Dongtai = db.xxxxx
return View(model);
—-
参数应该填什么啊?
—-
—-
—-
—-
—-
界面如何接收啊?
出现错误
—-
—- 30分
就可以了
—-
ZhuYecontrollers代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QunZhongLuXian.Models;//项目名称,引用自定义的Model
namespace QunZhongLuXian.Controllers
{
public class viewModel
{
public List<ZuZhiJiGou> zzjgModel { get; set; }
public List<LingDaoJiangHua> ldjhModel { get; set; }
public List<GongZuoDongTai> gzdtModel { get; set; }
public List<WenJianTongZhi> wjtzModel { get; set; }
public List<XueXiJiaoLiu> xxjlModel { get; set; }
public viewModel(List<Models.ZuZhiJiGou> zzjgList, List<Models.LingDaoJiangHua> ldjhList, List<Models.GongZuoDongTai> gzdtList, List<Models.WenJianTongZhi> wjtjList, List<Models.XueXiJiaoLiu> xxjlList)
{
this.zzjgModel = zzjgList;
this.ldjhModel = ldjhList;
this.gzdtModel = gzdtList;
this.wjtzModel = wjtjList;
this.xxjlModel = xxjlList;
}
}
public class ZhuYeController : Controller
{
QunZhongLuXianContext db = new QunZhongLuXianContext();
public ActionResult Index()
{
var vm = new viewModel(db.ZuZhiJiGous.ToList(), db.LingDaoJiangHuas.ToList(), db.GongZuoDongTais.ToList(), db.WenJianTongZhis.ToList(), db.XueXiJiaoLius.ToList());
vm.zzjgModel = db.ZuZhiJiGous.ToList();
vm.ldjhModel = db.LingDaoJiangHuas.OrderByDescending(p => p.ShiJian).ToList();
vm.gzdtModel = db.GongZuoDongTais.OrderByDescending(p => p.ShiJian).ToList();
vm.wjtzModel = db.WenJianTongZhis.OrderByDescending(p => p.ShiJian).ToList();
vm.xxjlModel = db.XueXiJiaoLius.OrderByDescending(p => p.ShiJian).ToList();
return View(vm);
}
}
}
对应/Views/ZhuYe/Index.cshtml视图代码(部分)
@using QunZhongLuXian.Models
@model QunZhongLuXian.Controllers.viewModel//引用ZhuYeControllers中自定义的viewModel类类型
中间省略,下面是通过Foreach循环显示两个Model的列表数据(分别是Model.ldjhModel和Model.gzdtModel)
<div class=”box”>
<h1>
<span><a href=”@Url.Action(“Index”, “LingDaoJiangHua”)”>more</a></span>领导讲话
</h1>
<ul>
@foreach (var item in Model.ldjhModel)
{
<li>
<span class=”datetime”>@item.ShiJian</span>
<a href=”@item.LuJing”>@item.BiaoTi</a>
</li>
}
</ul>
</div>
<div class=”box”>
<h1>
<span><a href=”@Url.Action(“Index”, “GongZuoDongTai”)”>more</a></span>工作动态
</h1>
<ul>
@foreach (var item in Model.gzdtModel)
{
<li>
<span class=”datetime”>@item.ShiJian</span>
<a href=”@item.LuJing”>@item.BiaoTi</a>
</li>
}
</ul>
</div>
—-
—-