Routes in MVC
Routes in MVC:
Route 可以用來 map URL 的 Request, 甚麼意思呢? 假設我現在我寫一個 blog 在我的網頁上, 這個時候可能的網址就是
https://mysite/blog/create
, 其中 blog 在 MVC 的 Routing table 眼裡, 他是一個 controller, create 表示這一個 blog controller 裡面會有一個 method(action) 方法叫做 create, 那麼我又突然想去找之前的文章修改一下, 當我按下編輯的按鈕, 而這顆按鈕背後的邏輯是去找 blog controller 裡面的 edit action, 那這一篇文章是 id = 5, 所以找到 id = 5 的那一個並顯示出來, 這麼一來 url 有可能是 https://mysite/blog/edit/5
, 簡單來說, routes 可以用簡單的 table 來表示
Routing Table
Controller | Action | Route | Code |
---|---|---|---|
Home | Index | /home | public Index() |
Home | Error | /home/error | public Error() |
Home | About | /home/about | public About() |
Blog | Index | /blog | public Index() |
Blog | Create | /blog/create | public Create() |
Blog | Post | /blog/post | public Post() |
留言
張貼留言