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 have two sets of data, one for Clients and one for the Vacancies of the clients. So In my table I have successfully created a button which when clicked displays Client results, this includes a ClientID and a Client Name. I have also linked in some Vacancy details where I manage to to tally the amount of vacancies they have in relation to the client. Right now I would like to create a fourth table header which is populated with links that will bring the user to another page which displays those vacancies, instead of just tallying them up in another header. I will paste the code (except from the data) to see if this helps. This is my 8th day of coding with MVC and still find it confusing at time. If you dont want to write the code, it would be helpful if you could tell me if I need another controller, or more models. Thank you.

Quote:


View:


<%
Dim oClient As VacancyManager2.DataModels.Client

For Each oClient In Model.SearchResults
%>
<%
Next
%>
Controller:

<httpget()>
Function IndexSearch() As ActionResult
Dim oModel As ViewModels.ClientSearch = New ViewModels.ClientSearch
oModel.SearchText = ""
oModel.SearchResults = New List(Of DataModels.Client)

Return View(oModel)
End Function

<httppost()>
Function IndexSearch(PostedInfo As FormCollection) As ActionResult
Dim sClientName = PostedInfo("ClientName")
Dim oModel As ViewModels.ClientSearch = New ViewModels.ClientSearch
oModel.SearchText = sClientName
Dim oClientList As DataModels.ClientList = New DataModels.ClientList
oModel.SearchResults = oClientList.SearchClients(sClientName)
Return View(oModel)


End Function

DataModel:

Public Class Client
Property ClientID As Integer
Property ClientName As String

Public Sub New(inClientID As Integer, inClientName As String)
Me.ClientID = inCLientID
Me.ClientName = inClientName
End Sub

Function NumberOfVacancies() As Integer
Dim oVacancyList As VacancyList = New VacancyList
Return oVacancyList.NumberOfVacancies(Me.ClientID)
End Function
End Class

Function SearchClients(inSearchFor As String) As List(Of Client)

Dim oResults As List(Of Client) = New List(Of Client)
Dim oClient As DataModels.Client
For Each oClient In Me.Clients
If LCase(oClient.ClientName).Contains(LCase(inSearchFor)) Then
oResults.Add(oClient)
End If
Next

Return oResults
End Function

Function ClientName(inClientID As Integer) As String
Dim sClientName As String = ""

Dim oClient As DataModels.Client
For Each oClient In Me.Clients
If oClient.ClientID = inClientID Then
sClientName = oClient.ClientName
Exit For
End If
Next

Return sClientName
End Function

ViewModel:

Public Class ClientSearch
Property SearchText As String
Property SearchResults As List(Of DataModels.Client)
End Class
Reference Client Name Number of Vacancies per Client Link for the vacancies
<%: oClient.ClientID%> <%: oClient.ClientName%> <%: oClient.NumberOfVacancies%> <%: Html.ActionLink("The Number of Vacancies", "IndexSearchNumOfVacancies", "ClientSearch")%>
Posted

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