博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ASP.NET MVC
阅读量:6954 次
发布时间:2019-06-27

本文共 1414 字,大约阅读时间需要 4 分钟。

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.

 

入门文章

 C1

 C2       

 C3

 

MVC官方入门例子

 

// GET: /HelloWorld/        #region  为Controller类添加Action方法        /*MVC默认的Mapping format*/        public string Index() //调用方式  Controller前缀/Index        {            return "this is default 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

Welcome

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

 

 

转载地址:http://lpvil.baihongyu.com/

你可能感兴趣的文章
树莓派(Debian)系统开启iptables的raw表实现日志输出
查看>>
图像滤镜实现万能方法研究
查看>>
nginx-启动gzip、虚拟主机、请求转发、负载均衡
查看>>
magento 2.3安装测试数据
查看>>
大数据开发实战:数据平台大图和离线数据平台整体架构
查看>>
Git 收集别名
查看>>
操作系统日志分析中常见的搜索条目 20160715
查看>>
《CLR via C#》笔记——异常和状态管理
查看>>
将matlab的figure保存为pdf,避免图片太大缺失
查看>>
Spring MVC 3 深入总结
查看>>
原创4:dell sc1425老服务器安装vmware虚拟机esxi 5.0-更新Dell SCSI Hard Drive Firmware
查看>>
JAVA多线程学习Runnable接口
查看>>
AE Geoprocessor 实现 AnalysisTool Union功能
查看>>
深入理解JVM
查看>>
微观ORACLE(一):PMON Release Lock
查看>>
NC57银行档案和客商银行账号为建行04 UPDATE
查看>>
(转)Objective-C的单例模式(singleton)
查看>>
细说 ASP.NET控制HTTP缓存(转)
查看>>
使用Vitamio打造自己的Android万能播放器(3)——本地播放(主界面、播放列表)...
查看>>
在网页div,table,p,span,body,等很多元素中输入内容.
查看>>