我想在首页上面放置很多栏目。每个栏目,我都做成了Usercontrol. 每个Usercontrol 都对应一个model .但是,我要把这些栏目的都放置在一个页面(首页)上,我这些数据,就要在显示首页的时候一次性全部取出。所以,我又手动添加了一个首页的model. 这个model.里面包含了各个UserControl 对应的Model. 我的想法是这样的。在首页Model里面包含各个Usercontrol所需要的数据,然后各个Usercontrol 再从这个首页model里面取出所需要的model数据。但是事实这样做。在首页插入Usercontrol的地方会报模型类型错误。
部分代码如下:
//首页模型
public class IndexModels
    {
        //关于我们
        public AboutUsModels aboutus = new AboutUsModels();
        
        //公司信息
        public CompanyIntroModels companyInfo = new CompanyIntroModels();        //产品展示
        public List<ProductShowModels> productShow = new List<ProductShowModels>();        //站内搜索
        public SearchModels search = new SearchModels();        //产品分类
        public List<ProductClassModels> productclass = new List<ProductClassModels>();        //主营业务
        public List<MainBusinessModels> mainbusiness = new List<MainBusinessModels>();        //联系我们
        public ContactUsModels contactus = new ContactUsModels();        //新产品展示
        public List<NewProductModels> newproduct = new List<NewProductModels>();
    }//控制器部分代码
public ActionResult Index()
        {
            ViewData["Message"] = "欢迎来到昆明奇妙锁业公司";            IndexModels indexmodel = new IndexModels();
            GetIndexInfo(indexmodel);            return View(indexmodel);
        }        //获取主页显示所需要的所有信息
        private void GetIndexInfo(IndexModels indexmodel)
        {
            GetAboutUsInfo(indexmodel);
            GetCompanyIntroInfo(indexmodel);
            GetProductShowInfo(indexmodel);
            GetProductClassInfo(indexmodel);
            GetMainBusinessInfo(indexmodel);
            GetContactUsInfo(indexmodel);
            GetNewProductInfo(indexmodel);
        }报错:
细信息: System.InvalidOperationException: 传入字典的模型项的类型为“LockCompany.Models.IndexModels”,但此字典需要类型“System.Collections.Generic.IEnumerable`1[LockCompany.Models.NewProductModels]”的模型项。
请熟悉MVC2.0的大哥指点小弟,小弟是新新手,说详细点,这种需要复用的模块该如何来做。我的做法是否有问题。谢谢!

解决方案 »

  1.   

    首页里是不是用的 html.renderPartial?,把 IndexModels.newproduct 传给你的 user control
      

  2.   

    你可以把 每个的Model放到ViewData中,再取出来
      <%Html.RenderPartial("Nav",ViewData[''] as Model1); %>
      

  3.   

    你可以把 每个的Model放到ViewData中,再取出来
      <%Html.RenderPartial("Nav",ViewData[''] as Model1); %>
      

  4.   

    对,就是对调用的这个。
    IndexModels 名字就是这个?
    我是打算这样做,但是,怎么没有智能提示?
      

  5.   


    html.renderpartial(Model.newproduct)