asp.net mvc控制器调用从一个控制器到另一个控制器的输入

时间:2013-04-22 14:44:31

标签: asp.net-mvc

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

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放在应该的位置并且它可以工作,但是它会从联系人那里写信息。

1 个答案:

答案 0 :(得分: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;