收录日期:2019/06/26 10:37:05 时间:2010-06-22 20:12:10 标签:asp.net-mvc,model-view-controller,asp.net-mvc-2

i'd like to map areas like this:

/artists/{artistName}/images
/artists/{artistName}/images/{imageId}
/artists/{artistName}/blogs
/artists/{artistName}/blogs/{blogId}
/artists/{artistName}/albums
/artists/{artistName}/albums/{albumId}

in mvc2, how do i configure my area route and what does my file structure for my area view look like?

thanks.

I would probably do something like this in your area registration:

Public Overrides ReadOnly Property AreaName() As String
            Get
                Return "Artists"
            End Get
        End Property

Public Overrides Sub RegisterArea(ByVal context As System.Web.Mvc.AreaRegistrationContext)
     context.MapRoute( _
          "Artists_default", _
          "Artists/{artistName}/{controller}/{id}/{action}", _
                New With {.id = UrlParameter.Optional, .action = "Index"} _
            )
End Sub

Treat images/blogs/albums as your controller. Put the action at the end of the string so that it will stay invisible if each of your examples is only one action.

EDIT: There is a second part to your question :)

By going this route, you will then have a folder structure like this

Areas
  Artists
     Controllers
          ImagesController
          BlogController
          AlbumsController
     Views
          Images
               Index
          Blog
               Index
          Albums
               Index

Your view folder name corresponds to a controller name, the view name itself typically corresponds with an action.