我创建了这条路线:
routes.MapRoute( _
"Pages", _
"Pages/{id}/{title}", _
New With {.controller = "Home", .action = "Pages", .id = UrlParameter.Optional, .title = UrlParameter.Optional} _
)
然后,我在“主页”控制器中创建了以下“页面”操作:
Function Pages(Optional ByVal id = 0, Optional ByVal title = "") As ActionResult
Dim db As NavDbContext = New NavDbContext
Dim page = db.Tbl_Navigations.Where(Function(p) p.NAV_ID = id)
If (page.Any) Then
Dim _title = page.Single.NAV_Element.ToString
Dim content = page.Single.NAV_Content.ToString
ViewBag.Title = _title
ViewBag.Content = content
End If
Return View()
End Function
当我导航到 ~/Pages/8/MyPage(这是我数据库中的有效 ID)时,它显示“找不到资源”。我怎样才能正确路由呢?谢谢。