control:
Function Index() As ActionResult
Dim search1 As String = "Beverages"
Dim search2 As String = "Cheeses"
' 空のコレクションを用意
Dim queryList As IEnumerable(Of
Categories) = New List(Of
Categories)()
If search1 <> "" Then
queryList = queryList.Union(db.Categories.Where(Function(v) v.CategoryName.Contains(search1)).ToList())
End If
If search2 <> "" Then
queryList = queryList.Union(db.Categories.Where(Function(c) c.Description.Contains(search2)).ToList())
End If
Dim all = queryList.ToList()’查看SQL用
Return View(all)
End Function
view:
@ModelType IEnumerable(Of VBLinqTest.Categories)
@Code
ViewData("Title") = "Index"
End Code
<h2>where 多条件 or 查询</h2>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(Function(model) model.CategoryName)
</th>
<th>
@Html.DisplayNameFor(Function(model) model.Description)
</th>
</tr>
@For Each item In Model
@<tr>
<td>
@Html.DisplayFor(Function(modelItem) item.CategoryName)
</td>
<td>
@Html.DisplayFor(Function(modelItem) item.Description)
</td>
</tr>
Next
</table>
http://www.atmarkit.co.jp/ait/articles/1412/16/news134.html