GetSiteMap()
という名前の関数を持つマスターページがあります。この関数は、現在の場所に基づいてカスタムマップをレンダリングするために使用されます。私の問題は、MVCでは、コードビハインドモデルを持たないため、この種の機能を公開していないことです。ASP.NET MVC関数呼び出し
これを行う正しい方法は何ですか?私はそれに定義されたその機能を持つ何らかの種類のマスターページコントローラを持っているべきですか?
Public Function GetSitemap() As String
Dim s As New SiteNavigation
Dim siteMapNodeCollection As SiteMapNodeCollection
If Not SiteMap.CurrentNode.Equals(SiteMap.RootNode) Then
If Not SiteMap.CurrentNode.HasChildNodes Then
' otherwise it'll go to the pseudo-current directory, which is wrong
Dim parentNode As SiteMapNode = SiteMap.CurrentNode.ParentNode.ParentNode
s.AddBackLink(parentNode.Url, parentNode.Title)
Else
Dim parentNode As SiteMapNode = SiteMap.CurrentNode.ParentNode
s.AddBackLink(parentNode.Url, parentNode.Title)
End If
End If
If Not SiteMap.CurrentNode.HasChildNodes Then
siteMapNodeCollection = SiteMap.CurrentNode.ParentNode.ChildNodes
Else
siteMapNodeCollection = SiteMap.CurrentNode.ChildNodes
End If
For Each siteMapNode As SiteMapNode In siteMapNodeCollection
GenerateLinks(siteMapNode, s)
Next
Return s.GetSiteNavigation()
End Function
Private Sub GenerateLinks(ByRef siteMapNode As SiteMapNode, ByRef siteNavigation As SiteNavigation)
If siteMapNode.Url.Length = 0 And siteMapNode.Description = "separator" Then
siteNavigation.AddSeparator()
ElseIf siteMapNode.Url.Length = 0 And siteMapNode.Description = "heading" Then
siteNavigation.AddHeading(siteMapNode.Title)
Else
siteNavigation.AddLink(siteMapNode.Url, siteMapNode.Description, siteMapNode.Title, siteMapNode.HasChildNodes)
End If
End Sub
申し訳ありませんが、これは私が言ったことです。先日私はこれを非常に素早く書きましたので、完璧ではありませんが、今は仕事をしています。私はサイトマップを使用していて、特定の要素にURLはなく、代わりに<li>
要素が別の方法でレンダリングされている(このHTML要素に別のクラスが適用されている)ことを示す「区切り記号」などの説明を与えています。
どこにGetSiteMap()を持っているコードは行くべきですか?それはSiteMapを表すカスタムクラスを使用します。 – Kezzer
コードはベースコントローラー自体に含まれる可能性があります。これは私の例で示したものです。サイトマップは、実際にはMVCアプリケーションのコントローラアクションの関数なので、私はコントローラとそれを保持すると思います。モデルにSiteMapを表すクラスを配置します。 – tvanfosson