码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET MVC4学习笔记

时间:2015-10-19 15:14:52      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

一、MVC简介

技术分享

 

技术分享

 

技术分享

备注:

过去MVC模式并不适合小型甚至中等规模的应用程序,这样会带来额外的工作量,增加应用的复杂性。但现在多数软件设计框架,能直接快速提供MVC骨架,供中小型应用程序开发,此问题不再存在。对于开发存在大量用户界面,并且逻辑复杂的大型应用程序,MVC将会使软件在健壮性、代码重用和结构方面上一个新的台阶。尽管在最初构建MVC模式框架时会花费一定的工作量,但从长远的角度来看,它会大大提高后期软件开发的效率。

技术分享

技术分享

 

二、First Demo

技术分享

 

技术分享

 

技术分享

 

技术分享

技术分享

 

技术分享

 

技术分享

 

三、Web开发方式对比

技术分享

 

技术分享

 

技术分享

 

技术分享

技术分享

 

四、View详解

技术分享

技术分享

 

技术分享

 

技术分享

 

技术分享

技术分享

技术分享

技术分享

技术分享

 

技术分享

 

五、Controller详解

技术分享

 

技术分享

技术分享

 

技术分享

 

技术分享

 

六、路由Route

技术分享

技术分享

技术分享

技术分享

技术分享

技术分享

技术分享

技术分享

备注:

如果使用的是RouteDebugger,则不需要在Global中注册,而是通过web.config中为appsettings添加子节点<add key="RouteDebugger:Enabled" value="true"/>

技术分享

备注:

 #region 路由规则示例
            //新闻显示页
            routes.MapRoute(
                name: "NewsShow",
                url: "News/{year}-{month}-{day}-{id}",
                defaults: new { controller = "NewsHome", action = "Show" },
                constraints: new { year = @"^\d{4}$", month = @"^\d{1,2}$", day = @"^\d{1,2}$" }
                );
            //新闻列表页
            routes.MapRoute(
                name: "NewsList",
                url: "News/{type}-{pageindex}-{pagesize}",
                defaults: new { controller = "NewsHome", action = "List" }
                );
            //新闻首页
            routes.MapRoute(
                name: "NewsIndex",
                url: "News/{*values}",
                defaults: new { controller = "NewsHome", action = "Index" }
                );
            //网站首页
            routes.MapRoute(
                name: "Index",
                url: "{*values}",
                defaults: new { controller = "Home", action = "Index" }
                );
            #endregion

 

技术分享

 

七、异步

技术分享

技术分享

技术分享

 

技术分享

 

八、校验

技术分享

 

技术分享

 

九、区域Area

技术分享

 

技术分享

 

十、过滤器

技术分享

 

技术分享

 

技术分享

 

技术分享

 

技术分享

技术分享

 

技术分享

 

技术分享

 

十一、模板页

技术分享

技术分享

 

技术分享

 

 

十二、WebAPI

技术分享

 

技术分享

 

技术分享

备注:

var data = ‘{"UserId":"‘ + $(‘#userId‘).val() +
               ‘","UserName":"‘ + $(‘#userName‘).val() + ‘"}‘;


                $.ajax({
                    type: ‘PUT‘,//请求类型。get,post,put,delete
                    url: ‘api/UserInfo/‘ + $(‘#userId‘).val(),//请求地址
                    data: data,//参数
                    contentType: "application/json; charset=utf-8",//数据类型
                    dataType: ‘text‘,//返回数据类型
                    success: function (msg) {
                        if (eval(msg) == ‘1‘) {
                            InitData();
                        }
                    }
                });

 

技术分享

备注:

创建并初始化对象:
    client.BaseAddress = new Uri(url);
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

读集合:
    HttpResponseMessage response = client.GetAsync(url).Result;
     var userList = response.Content.ReadAsAsync<IEnumerable<数据类型>>().Result;

根据编号读对象
    HttpResponseMessage response1 = client.GetAsync(url).Result;
    var userInfo = response1.Content.ReadAsAsync<数据类型>().Result;

增加:
    HttpResponseMessage response = client.PostAsJsonAsync("api/userinfo", userInfo).Result;
    使用response.IsSuccessStatusCode判断是否成功
    使用response.Content.ToString()获取返回值

修改:
     HttpResponseMessage response = client.PutAsJsonAsync("api/userinfo/"+userInfo.UserId, userInfo).Result;
    使用response.IsSuccessStatusCode判断是否成功
    使用response.Content.ToString()获取返回值

删除:
    HttpResponseMessage response = client.DeleteAsync("api/userinfo/" + uid).Result;
    使用response.IsSuccessStatusCode判断是否成功
    使用response.Content.ToString()获取返回值

 

十三、原理(管道执行过程)

技术分享

备注:

当一个asp.net mvc应用程序提出请求,为了响应请求,包含一些请求执行流程步骤! 在asp.net mvc应用程序Http request 和Http response 过程中,主要包含8个步骤:     

1)RouteTable(路由表)的创建     

2)UrlRoutingModule 请求拦截     

3)Routing engine 确定route     

4)route handler 创建相关的IHttpHandler实例     

5)IHttpHandler实例确定Controller(控制器)     

6)Controller执行     

7)一个视图引擎创建     

8) 视图呈现

技术分享

 

ASP.NET MVC4学习笔记

标签:

原文地址:http://www.cnblogs.com/zxx193/p/4891738.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!