asp.net mvc complex routing for tree path

后端 未结 4 1285
后悔当初
后悔当初 2020-11-29 23:17

I am wondering how can I define a routing map like this:

{TreePath}/{Action}{Id} 

TreeMap is dynamically loaded from a database like this:<

4条回答
  •  甜味超标
    2020-11-30 00:08

    You can have the "greedy" part within the querystring as long as you can have fixed parts after it, e.g.

    /{*TreePath}/Edit/{id}
    /{*TreePath}/Action/{id}
    

    Note that the action is not variable in the above routes because the greedy parts needs to stop at some literal value (other that forward slash). I will work if you only perform a few actions on your "tree" but will cumbersome if you have many action since each will need its own route entry.

    It will not work out of the box but requires a custom route. You can find a nice write on the subject including code here

提交回复
热议问题