@helper ShowTree(IEnumerable<CommentModel> comments) {
foreach (CommentModel c in comments)
{
// ...我不明白这是怎么回事。comments从哪里来?这到底是怎么回事?
我想从传递到视图的模型中递归地显示一个List<CommentModel>。列表中的每个项目都有自己的CommentModel列表,依此类推。这是用于呈现这些列表的正确方法吗?我如何使用它?
发布于 2013-12-03 17:25:54
在您的视图中,可以将注释作为参数传递:
@model IEnumerable<CommentModel>
@ShowTree(Model)
@helper ShowTree(IEnumerable<CommentModel> comments)
{
//your code...
}简单地说,您的操作方法可以是这样的:
public ActionResult Comments()
{
var query = _commentsService.GetAll();
return View("comments",query);
}https://stackoverflow.com/questions/20357639
复制相似问题