【发布时间】:2018-10-12 12:16:29
【问题描述】:
我正在尝试输出一组带有特定主题标签的推文。
我在控制器中有以下代码:
public ActionResult Test() {
var service = new TwitterService("xxx", "xxx");
service.AuthenticateWith("xxx", "xxx");
var options = new SearchOptions { Q = "#test" };
TwitterSearchResult tweets = service.Search(options);
IEnumerable<TwitterStatus> status = tweets.Statuses;
ViewBag.Tweets = status;
//var tweets = service.Search(options);
return View();
}
我想在视图中输出 IEnumerable 中的结果。 但是我发现很难在视图中输出这些结果。有人可以帮忙吗?
【问题讨论】:
-
你有什么问题(你甚至没有显示你查看代码)?
-
我卡住了,我不知道我应该从哪里开始显示这个!
-
首先删除
ViewBag.Tweets = status;并使用return View(status);然后在视图中使用@model IEnumerable<TwitterStatus>并使用循环显示您想要的集合中每个项目的内容 -
我认为使用 return View(status) 会导致一个只有 Twitter 提要的视图,对吧?我不希望我的视图只包含提要。
-
然后创建一个包含
IEnumerable<TwitterStatus>属性的视图模型并将其传递给视图。你的问题既不清楚又太宽泛。您需要做一些研究以了解 MVC 的基础知识,并在遇到特定问题时回来
标签: asp.net-mvc twitter tweetsharp