0

我有一个详细信息页面,它返回一个基本用于从数据库中查找页码的配置文件视图。我还有一个单独的查询,我想在返回视图中返回,但不知道怎么做。我的代码是

public ActionResult detail(int id)
    {
        profile profile = db.profiles.Find(id);
        var currentpage = (from s in db.profiles where id == s.profileID select s.registrationID).FirstOrDefault();
        var articles = (from s in db.Articles where currentpage == s.RegistrationID select s.title).FirstOrDefault();
        ViewBag.articles = articles;


        ViewBag.noprofiler = " This profile currently doesn't have the email profiler selected";




        return View(profile);
    }

我也想退回文章,我把它放进了一个viewbag但这没有任何想法?

4

1 回答 1

0

如果文章已填充,那么您应该能够通过 ViewBag.articles 在视图中访问它

也许您应该检查控制器函数中的文章变量中的内容。

变量名文章也建议您正在寻找一个列表,但您正在使用 FirstOrDefault() 它将返回单个对象(或 null)。

于 2012-09-29T00:59:56.630 回答