#眉標=ASP.NET、Silverlight、REST #副標=ASP.NET MVC Framework開發與應用(1) #大標=ASP.NET MVC 1.0初探 #作者=文/圖 董大偉 ============= 程式1 Protected Sub Button_GetBMI_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button_GetBMI.Click Dim BMI As Single Dim height, weight As Single '從UI取得身高體重 height = Me.TextBox_Height.Text weight = Me.TextBox_Weight.Text '計算BMI BMI = weight / (height / 100) ^ 2 '顯示BMI Me.Label_Result.Text = "計算結果 BMI=" & BMI End Sub ================ ===<反灰>============= BMI = weight / (height / 100) ^ 2 ================ ============= 程式2 Public Class BMI Private _Height As Single Public Property Height() As Single Get Return _Height End Get Set(ByVal value As Single) _Height = value End Set End Property Private _Weight As Single Public Property Weight() As Single Get Return _Weight End Get Set(ByVal value As Single) _Weight = value End Set End Property Function GetBmi() As Single Dim BMI As Single BMI = Weight / (Height / 100) ^ 2 Return BMI End Function End Class ================ ============= 程式2 Protected Sub Button_GetBMI_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button_GetBMI.Click   Dim oBMI As New BMI   Dim BMI As Single   Dim height, weight As Single '從UI取得身高體重   height = Me.TextBox_Height.Text weight = Me.TextBox_Weight.Text '計算BMI oBMI.Height = height oBMI.Weight = weight BMI = oBMI.GetBmi() '顯示BMI Me.Label_Result.Text = "計算結果 BMI=" & BMI End Sub ================ ============= 程式4:Views\Home\Index.aspx <%@ Page Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> Home Page

<%= Html.Encode(ViewData("Message")) %>

To learn more about ASP.NET MVC visit http://asp.net/mvc.

================ ============= 程式5:Controllers\HomeController.vb _ Public Class HomeController Inherits System.Web.Mvc.Controller Function Index() As ActionResult ViewData("Message") = "Welcome to ASP.NET MVC!" Return View() End Function   (…略…) End Class ================ =====線上影音教學 ========== 在此教學影片中,筆者將以Step By Step的方式介紹如何以ASP.NET MVC 1.0的專案範本,來建置一個基礎的MVC應用程式,並且說明專案中Model-View-Controller三塊程式碼的架構和彼此之間的關係。請連線至: ●RUN!PC網站:www.runpc.com.tw/content/main_content.aspx?mgo=184&fid=E00n ●筆者BLOG:blog.studyhost.com ==========