在WebGrid MVC中添加新列

时间:2015-09-30 07:07:31

标签: asp.net-mvc vb.net razor webgrid

在我的剃刀视图中,我有一组想要在网格中显示的对象。我可以在所有字段中执行此操作,但是当我想删除一些字段并添加更多源代码(集合)时,我得到'Column "DaysLeft" does not exist'

我的代码:

@code

ViewData("Title") = "Index"

Dim grid = New WebGrid(source:=Model, defaultSort:="proj_created_time")


Dim ListOfColumns As List(Of WebGridColumn) = New List(Of WebGridColumn)
Dim ProjectTitle As WebGridColumn = grid.Column("project_title")
ProjectTitle.Header = "Title"
Dim ProjectStatus As WebGridColumn = grid.Column("proj_status")
ProjectStatus.Header = "Status"
Dim ProjectInitialDate As WebGridColumn = grid.Column("proj_initial_duedate")
ProjectInitialDate.Header = "Starting Date"
Dim ProjectNewdueDate As WebGridColumn = grid.Column("proj_new_duedate")
ProjectNewdueDate.Header = "Due Date"

Dim DaysLeftCol As New WebGridColumn With {.ColumnName = "DaysLeft", .Header = "DaysLeft"}

ListOfColumns.Add(ProjectTitle)
ListOfColumns.Add(ProjectStatus)
ListOfColumns.Add(ProjectInitialDate)
ListOfColumns.Add(ProjectNewdueDate)
ListOfColumns.Add(DaysLeftCol)

结束代码


@grid.GetHtml(columns:=ListOfColumns, tableStyle:="table")

有什么想法?

1 个答案:

答案 0 :(得分:0)

解决方案与此类似

        Dim ProjectDownload As WebGridColumn = grid.Column(header:="Attachement", columnName:="project_ID", format:=Function(item)
                                                                                                                        If item.project_attachement.count > 0 Then

                                                                                                                            Dim newLink As HtmlString
                                                                                                                            For Each down In item.project_attachement
                                                                                                                                Dim chec = down.project_ID & " " & down.project_atta_name
                                                                                                                                newLink = New HtmlString(helper.ActionLink("Download", "FileDownload", "Project", New With {.id = down.project_ID, .name = down.project_atta_name}).ToString)
                                                                                                                                Return newLink
                                                                                                                            Next

                                                                                                                        Else
                                                                                                                            Return "No File"
                                                                                                                        End If
                                                                                                                    End Function, canSort:=False)