ASP.NET MVC

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>
原文地址:https://www.cnblogs.com/imihiroblog/p/2576908.html