#眉標=ASP.NET、MVC、Url-Routing #副標=ASP.NET MVC Framework開發與應用(2) #大標=Controller與Url-Routing的架構與用途 #作者=文/圖 董大偉 ============= 程式1: Global.asax.vb Public Class MvcApplication Inherits System.Web.HttpApplication Shared Sub RegisterRoutes(ByVal routes As RouteCollection) routes.IgnoreRoute("{resource}.axd/{*pathInfo}") routes.MapRoute("Default", "{controller}/{action}/{id}", _ New With {.controller = "Home", .action = "Index", .id = ""} ) End Sub Sub Application_Start() RegisterRoutes(RouteTable.Routes) End Sub End Class ================ ===<反灰>============= New With {.controller = "Home", .action = "Index", .id = ""} ================ ============= 程式2 ' POST: /Bmi/Index _ Function Index(ByVal TxbHeight As Single, ByVal TxbWeight As Single) As ActionResult Dim BMI As Single Dim MyBMI As New BMI '使用BMI類別進行運算 MyBMI.Height = TxbHeight MyBMI.Weight = TxbWeight BMI = MyBMI.GetBMI() '將執行結果傳遞給View ViewData("result") = BMI '使用預設的VIew Return View() End Function ================ ============= 程式3 Public Class ProductController Inherits System.Web.Mvc.Controller Function ShowDetails(ByVal id As String) As ActionResult '邏輯運算程式碼 '…(略)… Return View() End FunctionEnd Class ================ ============= 程式4 ' POST: /Bmi/Index _ Function Index(ByVal TxbHeight As Single, ByVal TxbWeight As Single) As ActionResult (…略…) End Function ================ ============= 程式5 ' GET: /Bmi/Index Function Index() As ActionResult Return View() End Function ================ ============= 程式6 _ Function ShowDetails(ByVal id As String, ByVal FormData As FormCollection) As ActionResult (…略…) Return View() End Function ================ =====線上影音教學 ========== ●RUN!PC網站:www.runpc.com.tw/content/main_content.aspx?mgo=186&fid=E07 ●筆者BLOG:blog.studyhost.com ==========