我有两组数据,一组用于客户端,另一组用于客户的空缺。因此,在我的表中,我已成功创建了一个按钮,单击该按钮时显示客户端结果,其中包括ClientID和客户端名称。我还在一些空缺细节中链接了我设法计算他们与客户有关的空缺数量。现在我想创建一个第四个表头,其中填充了一些链接,这些链接会将用户带到显示这些空位的另一个页面,而不是仅仅在另一个标题中计算它们。我将粘贴代码(数据除外),看看这是否有帮助。这是我使用MVC进行编码的第8天,但仍然发现它很混乱。如果您不想编写代码,如果您能告诉我是否需要其他控制器或更多型号,将会很有帮助。谢谢。
查看:
<table>
<thead>
<tr>
<th> Reference </th>
<th> Client Name </th>
<th> Number of Vacancies per Client </th>
<th> Link for the vacancies </th>
</tr>
</thead>
<tbody>
<%
Dim oClient As VacancyManager2.DataModels.Client
For Each oClient In Model.SearchResults
%>
<tr>
<td><%: oClient.ClientID%></td>
<td><%: oClient.ClientName%></td>
<td><%: oClient.NumberOfVacancies%></td>
<td><%: Html.ActionLink("The Number of Vacancies", "IndexSearchNumOfVacancies", "ClientSearch")%></td>
</tr>
<%
Next
%>
</tbody>
控制器:
<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
视图模型:
Public Class ClientSearch
Property SearchText As String
Property SearchResults As List(Of DataModels.Client)
End Class