首页 > Web开发 > 详细

ASP.NET MVC 学习1、新增Controller,了解MVC运行机制

时间:2014-03-05 06:26:38      阅读:457      评论:0      收藏:0      [点我收藏+]

1,turorial ,根据以下教程新建一个MVC项目

First Page:

bubuko.com,布布扣            

2,M-V-C:

  Models: 存放数据模型(Model Data),验证接收的数据(Validation Logic)

  Views:  用户看到的HTML页面 (dynamically genetate HTML Page)

  Controls:处理用户请求,从Models中检索数据以后,指定View页面输出(specify View templates)到浏览器

Add a new controller:

bubuko.com,布布扣

3, 了解MVC运行机制

   MVC 根据不同的URL请求,调用相应controller class 中的相应的action methods .默认的调用路径是:/[Controller]/[ActionName]/[Parameters]

http://localhost:9898/helloWorld/index /helloworld/index

http://localhost:9898/helloWorld/welcome /helloworld/welcome

上面的路径,MVC的路由机制会从helloworldController控制器中找到index方法和welcome方法,直接显示HTML页面。路径中没有Parameters

 

更新Controller中的Welcome方法如下

public string Welcome(string name, int numTimes = 1) {

     return HttpUtility.HtmlEncode("Hello " + name + ", NumTimes is: " + numTimes);}

浏览器地址手动更新为:http://localhost:9898/helloWorld/Welcome?name=Spring&numtimes=8

参数即被传递到页面中:

bubuko.com,布布扣

 

参考:

http://www.asp.net/mvc/tutorials/mvc-4

http://pluralsight.com/training/Player?author=scott-allen&name=mvc4-building-m1-intro&mode=live&clip=0&course=mvc4-building (mvc4 video)

ASP.NET MVC 学习1、新增Controller,了解MVC运行机制,布布扣,bubuko.com

ASP.NET MVC 学习1、新增Controller,了解MVC运行机制

原文:http://www.cnblogs.com/siri/p/3580693.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!