ASP.NET MVC

來源:互聯網
上載者:User

Model:資料和商務規則  data and business rules

View: 結果展示   output and representation

Controller:  把使用者輸入  轉變成 Model能處理的資料

 

訪問localhost/Home/index.aspx,

實際機制:HomeControl.cs中的 Action index;

返回機制:返回Views/Controller/index.aspx

總結:請求aspx時,是請求control類下的action方法

         返回views時,是返回View目錄下的Control類的action.aspx.

 

入門文章

 C1http://www.cnblogs.com/QLeelulu/archive/2008/09/30/1302462.html

 C2http://www.cnblogs.com/QLeelulu/archive/2008/10/03/1303521.html       

 C3http://www.cnblogs.com/QLeelulu/archive/2008/10/03/1303612.html

 

MVC官方入門例子

http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/intro-to-aspnet-mvc-3

 

        // GET: /HelloWorld/        #region  為Controller類添加Action方法        /*MVC預設的Mapping format*/        public string Index() //調用方式  Controller首碼/Index        {            return "this is <b>default</b> action";        }        //public string Welcome() //調用方式  Controller首碼/Welcome        //{        //    return "this is Welcome action";        //}        //http://localhost:7391/HelloWorld/Welcome?name=Scott&numtime=1  //調用時,url的參數名必須和形參同名        public string Welcome(string name, int numtime) //在Control中不許出現函數重載,        {            return "Hello " + name + "numTime is:" + numtime.ToString();        }        #endregion 

 

  △ Controller解析URL和參數, 將結果寫到ViewData(索引值對),ViewBag中,View再產生結果頁面

  

public class HelloWorldController:Controller{        public ActionResult Welcome(string name, int numtime)        {            ViewData["Message"] = "Hello " + name;            ViewData["Numtime"] = numtime;            return View();        }}

 

 WelCome.aspx

    <h2>Welcome</h2>    <ul>       <%for (int i = 0; i <= Convert.ToInt32(ViewData["numtime"]); i++) {%>            <li><%=ViewData["Message"].ToString()%></li>       <%}%>     </ul>

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.