0

例如:我有控制器,联系我有的地方:

public ActionResult Index(string alias = "")
{      
    var list = db2.Pages.ToList();
    var PageModel = list.Where(x => x.PageModelID == 14).SingleOrDefault();

    ViewData["ContactTitle"] = PageModel.Title;
    ViewData["ContactContent"] = PageModel.Content;

    return View(ViewData);
}

我想添加页脚控制器,所以我创建了它,如下所示:

public ActionResult Index(string alias = "")
{
    var list = db.Pages.ToList();
    var PageModel = list.Where(x => x.PageModelID == 15).SingleOrDefault();

    ViewData["FooterContent"] = PageModel.Content;

    return View(ViewData);
}

现在我想将 footercontroller 添加到每个其他控制器,在我看来一切都很好,你将 response.write 放在它应该在的位置并且它可以工作,但它会写入来自联系人的信息。

4

1 回答 1

0
  public ActionResult Index(string alias = "") {

    var list = db2.Pages.ToList();
    var PageModel = list.Where(x => x.PageModelID == 14).SingleOrDefault();
    ViewData["ContactTitle"] = PageModel.Title;
    ViewData["ContactContent"] = PageModel.Content;

        var FooterModel = list.Where(x => x.PageModelID == 15).SingleOrDefault();
        ViewData["FooterContent"] = FooterModel.Content;
    return View(ViewData);
}      

在页脚控制器中,

       var FooterModel = list.Where(x => x.PageModelID == 15).SingleOrDefault();
        ViewData["FooterContent"] = FooterModel.Content;
于 2013-04-22T15:20:48.620 回答