简体   繁体   English

mvc 3与其他对象一起返回视图

[英]mvc 3 return view with other objects

I have a details page that returns a profile view that is basically used to find the page number from the database. 我有一个详细信息页面,该页面返回一个概要文件视图,该视图基本上用于从数据库中查找页码。 I also have a separate query that I would like to return in the return view but cannot figure out how to. 我也有一个单独的查询,我想在返回视图中返回,但无法弄清楚该怎么做。 The code I have is 我的代码是

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);
    }

i would like to also return articles i put it into a viewbag but that is not working any ideas ? 我想还回到文章中,我把它变成一个viewbag,但不工作的任何想法?

If articles is populated then you should be able to access it in the view via ViewBag.articles 如果文章被填充,那么您应该能够通过ViewBag.articles在视图中访问它

Maybe you should check what is in the articles variable here in the controller function. 也许您应该检查控制器功能中articles变量中的内容。

Also the variable name articles suggests you're looking for a list but you are using FirstOrDefault() which would return a single object (or null). 此外,变量名文章还建议您在寻找列表,但您使用的是FirstOrDefault(),它将返回单个对象(或null)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM