【问题标题】:Show listview from viewbag's list in MVC4在 MVC4 中从 viewbag 的列表中显示列表视图
【发布时间】:2014-05-28 06:26:20
【问题描述】:

我在控制器的viewbag中列出了如下列表:

List<TEAMS_PP.Entity.account> list = new TeacherEval().AllTechersList();
            ViewBag.allteacherlist = list;

我已确保该列表确实出现在 ViewBag.allteacherlist 中。

我想在视图页面(cshtml)的列表视图中显示它

我做了以下代码:

@(Html.Kendo().ListView<ViewBag.allteacherlist>()
    .Name("ListView")
    .TagName("div")
    .ClientTemplateId("template")
    .DataSource(dataSource => dataSource
        .Read(read => read.Action("Products_Read", "Home")) // Specify the action method and controller name
    )
    .Pageable()
)

但我无法在此处访问 viewbag.allteacherlist。

我只想在页面的viewbag中显示列表。

我能做什么???

请帮帮我。

【问题讨论】:

    标签: c# asp.net .net asp.net-mvc-4


    【解决方案1】:

    这是正确的语法

    @(Html.Kendo().ListView<TEAMS_PP.Entity.account>(ViewBag.allteacherlist as IEnumerable<TEAMS_PP.Entity.account>)
        .Name("ListView")
        .TagName("div")
        .ClientTemplateId("template")
        .DataSource(dataSource => dataSource
            .Read(read => read.Action("Products_Read", "Home")) // Specify the action method and controller name
        )
        .Pageable()
    )
    

    【讨论】:

      【解决方案2】:

      试试这个:

      @(Html.Kendo().ListView<(List<TEAMS_PP.Entity.account>)ViewBag.allteacherlist>()
          .Name("ListView")
          .TagName("div")
          .ClientTemplateId("template")
          .DataSource(dataSource => dataSource
              .Read(read => read.Action("Products_Read", "Home")) // Specify the action method and controller name
          )
          .Pageable()
      )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-04-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多