Asp.net MVC 中一对多关系的路由

发布于 2024-12-01 04:53:34 字数 846 浏览 1 评论 0原文

我有两个控制器

1)ServerController

2)ClientController

这两个控制器都有操作

ServerList,ClientList

AddServer,AddClient

DeleteServer,DeleteClient

,我想遵循休息原则,所以网址应该像这样

http://mydomain/Server/ServerList 将显示所有服务器列表

现在对于特定的 serverid 可能有很多客户端,因此 url 应该是 http://mydomain/Server/serverid(say:1)/Client/ClientList 将显示 serverid 1 的所有客户端列表

http://mydomain/Server/Add 将添加服务器

对于客户来说也是如此......

http://mydomain//Server/id/Delete 这将删除 id 的服务器,

同样删除客户端.. ...

请告诉我应该如何为此编写路线, 提前致谢...

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

http://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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软甜啾 2024-12-08 04:53:34

实现这种情况后,我真的发现了这些东西

1)根据休息原则这些网址将像这样

server/addserver,server/serverid/addclient
//添加服务器和添加客户端(为该服务器添加特定客户端)

server/serverlist,server/serverid/clientlist
//显示服务器列表和客户端列表(针对特定服务器ID显示所有客户端列表)

server/serverid/deleteserver,server/serverid/client
//删除服务器和客户端(对于特定的服务器ID删除所有客户端)

,我很高兴地说,一切都在单一路由下,

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

这就是我正在寻找的解决方案。
谢谢

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文