tags:

views:

250

answers:

2

I have a PartsController with the following partial code:

Function Search(ByVal searchtext As String, ByVal SearchType As String) As ActionResult

If SearchType = "PARTNAME" Then
Dim SearchResult = From p In _entities.PartList _
Where p.PARTNAME = searchtext _
Select p
Return View()
End If
If SearchType = "NSN" Then
Dim SearchResult = From p In _entities.PartList _
Where p.NSN = searchtext _
Select p
Return View()
End If
Return View("UnknownType")
End Function
Function Result(ByVal id As String, ByVal SearchResult As String) As ActionResult
Return View(SearchResult)

End Function

My SearchResult view is stored in Views/Parts/SearchResult.aspx. However, when I run the application, I receive Resource Cannot Be Found Requested URL /PartsController/Search

Question 2: Can someone point me to VB tutorial(s) that display results of a search in a view? That is, I need examples of how to put together the SearchResult view so that it retrieves only the items from my table where there's a match in the search string.

Thanks much for your help!

Global.asax:

' Note: For instructions on enabling IIS6 or IIS7 classic mode, 
' visit http://go.microsoft.com/?LinkId=9394802

Public Class MvcApplication
Inherits System.Web.HttpApplication

Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
routes.IgnoreRoute("{resource}.axd/{*pathInfo}")

' MapRoute takes the following parameters, in order:
' (1) Route name
' (2) URL with parameters
' (3) Parameter defaults
routes.MapRoute( _
"Default", _
"{controller}/{action}/{id}", _
New With {.controller = "Home", .action = "Index", .id = ""} _
)
routes.MapRoute( _
"Root", _
"", _
"(controller)/(action)/(id)", _
New With {.controller = "Home", .action = "Index", .id = ""} _
)
End Sub

Sub Application_Start()
RegisterRoutes(RouteTable.Routes)
End Sub
End Class

Note that this app is running on a Windows 2003 server (IIS6). Are there any further modifications I should make to global.asax?

Thanks Again, Sid

+1  A: 

Did you try the url: /Parts/Search ?

For the search results, your model/data context should contain a function that accepts the search criteria as a param, and returns the matching result.

something like:

Function AddQuerySearchCriteria(ByVal query As IQueryable, ByVal searchCriteria As SearchCriteria) As IQueryable
        If Not String.IsNullOrEmpty(searchCriteria.Keyword) Then
            Dim keyword As String = searchCriteria.Keyword.ToLower
            query = query.Where(customer=, Greater, (customer.FirstName.ToLower.Contains(keyword))
        End If
        Return query
End Function

Then your controller will call this function to return data to the SearchResults view.

Skelly
Is this something I can add to a module inside my Models folder? Or is there another preferred place to insert this code?
SidC
It depends on your setup, but it would most likely go into your Parts model. (ie; Model/Parts.vb)
Skelly
Thanks much! I created Parts.vb already and will add similar code to what you have suggested above. Any tutorials/links you've found helpful? A lot of the MVC stuff seems to be written in C# instead of VB :(
SidC
+1  A: 

Try this url: http://servername/Parts/Search , note I removed the Controller suffix. Under default routing configuration, you need to omit Controller part of the concrete controller class name

Because you didn't provide enough information, it's hard to tell exactly what's the cause. One of most common reason is improper configurations in iis. Please refer to this: Using ASP.NET MVC with Different Versions of IIS

Regarding vb tutorial, it's available here: http://www.asp.net/learn/mvc/tutorial-21-vb.aspx

Raymond