我有一個詳細信息頁面,返回配置文件視圖,基本上用於從數據庫中查找頁碼。我也有一個單獨的查詢,我想返回返回視圖但無法弄清楚如何。我的代碼是mvc 3與其他對象的返回視圖
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,但不工作的任何想法?
文章應該可用,如果您將其添加到ViewBag,只要它被分配在控制器中的值。您可能在視圖中使用的代碼訪問ViewBag中的文章時出現問題。你能否通過你曾經使用過的視圖代碼來做到這一點? –