I am creating an application in MVC in which I am displaying a list of rows in a table. I initially had it displaying all items but now what I want to do is to display certain items where the ID of the user is equal to the ID of the user in the Table.
I had it displaying like this:
In my Controller:
Public Function IssueHistory(sortOrderProject As String, command As String, issueTable As IssueTable) As ActionResult
Dim issues As IQueryable(Of IssueTable) = dbServer.IssueTables
Return View(issues)
End Function
I also have it ordered in alphabetical order like this:
If sortOrderProject Is Nothing Then
sortOrderProject = "AlphUp"
End If
Select Case sortOrderProject
Case "AlphDown"
ViewBag.AlphOrderIssue = "AlphUp"
issues = issues.OrderByDescending(Function(i) i.IssueTable.IssueKey)
Exit Select
Case "AlphUp"
ViewBag.AlphOrderIssue = "AlphDown"
issues = issues.OrderBy(Function(i) i.IssueTable.IssueKey)
Exit Select
Case Else
ViewBag.AlphOrderIssue = "AlphUp"
issues = issues.OrderBy(Function(i) i.IssueTable.IssueKey)
Exit Select
End Select
In my View:
@ModelType IEnumerable(Of IssueTable)
@Html.DisplayFor(Function(modelItem) item.IssueStatus)
@Html.DisplayFor(Function(modelItem) item.IssueStatus)
But how can I filter my application so that for each user ID in the IssueTable using a viewModel. This is what I have got so far:
Public Function IssueHistory(sortOrderProject As String, command As String, issueTable As IssueTracker.ClientUserProjectIssue) As ActionResult
Dim issues As IQueryable(Of IssueTracker.ClientUserProjectIssue) = dbServer.IssueTables
Return View(issues)
End Function
In my view:
@ModelType IEnumerable(Of IssueTracker.ClientUserProjectIssue)
@Html.DisplayFor(Function(modelItem) item.IssueTable.IssueStatus)
@Html.DisplayFor(Function(modelItem) item.IssueTable.IssueStatus)
My ViewModel looks like this:
Public Class ClientUserProjectIssue
Public Property uTable As UserTable
Public Property IssueTable As IssueTable
End Class
But then when I try to do it like this I get a lot of null values. What would be the correct way of filtering rows for each UserID that equals the UserID in the IssueTable using a viewModel?
I tried to implement it like this but have been unsuccessful
ViewModel:
Public Property iEnumarableIssue As IEnumerable(Of IssueTable)
Controller:
Dim ViewModel As IEnumerable(Of IssueTable) = dbServer.IssueTables
I can use IQueryable or IEnumerable if that is the correct way of doing it and the code can be explained in c#.