Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
VB
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:
VB
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:
VB
@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:
VB
Public Function IssueHistory(sortOrderProject As String, command As String, issueTable As IssueTracker.ClientUserProjectIssue) As ActionResult
    Dim issues As IQueryable(Of IssueTracker.ClientUserProjectIssue) = dbServer.IssueTables
    'Dim issues As IEnumerable(Of IssueTracker.ClientUserProjectIssue) = dbServer.IssueTables
    Return View(issues)
End Function

In my view:
VB
@ModelType IEnumerable(Of IssueTracker.ClientUserProjectIssue)
@Html.DisplayFor(Function(modelItem) item.IssueTable.IssueStatus)
@Html.DisplayFor(Function(modelItem) item.IssueTable.IssueStatus)

My ViewModel looks like this:
VB
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:
VB
Public Property iEnumarableIssue As IEnumerable(Of IssueTable)

Controller:
VB
Dim ViewModel As IEnumerable(Of IssueTable) = dbServer.IssueTables
'ViewModel.iEnumarableIssue  = dbServer.IssueTable.Where(Function(x) x.UserID= id).ToList()

I can use IQueryable or IEnumerable if that is the correct way of doing it and the code can be explained in c#.
Posted
Updated 10-Aug-15 22:48pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900