开发者

Routing for One to Many Relationship in Asp.net MVC

I am having two Controllers

1)ServerController

2)ClientController

Both of These are having actions

ServerList,ClientList

AddServer,AddClient

DeleteServer,DeleteClient

and I want to follow rest principle so urls should be like this

h开发者_开发知识库ttp://mydomain/Server/ServerList which will display all server list

Now for Specific serverid there can be so many clients so url should be http://mydomain/Server/serverid(say:1)/Client/ClientList which will display all client list for serverid 1

http://mydomain/Server/Add which will add a Server

Same for Client....

http://mydomain//Server/id/Delete which will delete server for id

Same delete for client.....

Please tell me How should I Write Routes for This, Thanks in Advance...


After implementing this situation I really found these things

1)According to rest principle these urls will be like this

server/addserver,server/serverid/addclient
//to add server and addclient(to add specific client for that server)

server/serverlist,server/serverid/clientlist
//displaying serverlist and clientlist(for a specific serverid display all clientlist)

server/serverid/deleteserver,server/serverid/client
//deletes server and client(for a specific serverid delete all clients)

and i'm glad to say guys that everthing was under a single route

         routes.MapRoute(
        "Default",
        "{controller}/{id}/{action}",
        new { controller = "Server",id=UrlParameter.Optional ,action = "ServerList" );// Default parameters which will redirect us to ServerList.

That was the solution I was looking for.
Thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜