ASP.net MVC资源无法找到

时间:2009-12-15 06:35:27

标签: asp.net-mvc

我有一个带有以下部分代码的PartsController:

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

我的SearchResult视图存储在Views / Parts / SearchResult.aspx中。但是,当我运行应用程序时,我收到资源无法找到请求的URL / PartsController / Search

问题2:有人能指出我在视图中显示搜索结果的VB教程吗?也就是说,我需要有关如何将SearchResult视图放在一起的示例,以便它只检索我的表中搜索字符串中匹配的项目。

非常感谢你的帮助!

的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

请注意,此应用程序正在Windows 2003服务器(IIS6)上运行。我应该对global.asax做进一步的修改吗?

再次感谢, SID

2 个答案:

答案 0 :(得分:1)

您是否尝试过网址:/部件/搜索?

对于搜索结果,您的模型/数据上下文应包含一个接受搜索条件作为参数的函数,并返回匹配结果。

类似的东西:

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

然后您的控制器将调用此函数将数据返回到SearchResults视图。

答案 1 :(得分:1)

试试这个网址:http://servername/Parts/Search,请注意我删除了控制器后缀。在默认的routing配置下,您需要省略具体控制器类名称的控制器部分

由于您没有提供足够的信息,因此很难准确说明原因是什么。最常见的原因之一是iis中的配置不正确。 请参阅:Using ASP.NET MVC with Different Versions of IIS

关于vb教程,可在此处找到:http://www.asp.net/learn/mvc/tutorial-21-vb.aspx