System.Web.Mvc.Controller的成员:HttpContext, Request, Response, Session, User都跟WebForm下的类似.
Request.QueryString,Request.Form,Request.Cookies,RouteData.Values等.
B:ASP.NET MVC3自带的ViewData,ViewBag,TempData
- usingSystem.Web.Mvc;
- namespaceMvcApplication1.Controllers
- {
- publicclassParamsController: Controller
- {
- stringinputBlank = "你输入了空白";
- publicActionResultIndex()
- {
- returnView();
- }
- //默认是处理Get请求,当然你也可以显式添加
- [HttpGet]
- publicActionResultUsingViewBag()
- {
- returnView();
- }
- //显式将操作方法设置处理Post请求
- [HttpPost]
- publicActionResultUsingViewBag(stringinput)
- {
- if(string.IsNullOrWhiteSpace(input))
- {
- ViewBag.Msg = inputBlank;
- }
- else
- {
- ViewBag.Msg = "你输入了: "+ input;
- }
- returnView();
- }
- publicActionResultUsingViewData()
- {
- returnView();
- }
- [HttpPost]
- publicActionResultUsingViewData(stringinput)
- {
- if(string.IsNullOrWhiteSpace(input))
- {
- ViewData["msg"] = inputBlank;
- }
- else
- {
- ViewData["msg"] = "你输入了: "+ input;
- }
- returnView();
- }
- publicActionResultUsingTempData()
- {
- returnView();
- }
- [HttpPost]
- publicActionResultUsingTempData(stringinput)
- {
- if(string.IsNullOrWhiteSpace(input))
- {
- TempData["msg"] = inputBlank;
- }
- else
- {
- TempData["msg"] = "你输入了: "+ input;
- }
- returnView();
- }
- }}
更详细的讨论,或许得另写一遍文章了.下一篇写Model,另外关于@Html的扩展方法,我打算另外写一篇去介绍.
IV:源代码下载
498)this.width=498;'' onmousewheel = ''javascript:return big(this)'' alt="" src="/uploadfile/201301/7/1295021648.png" />
原文:http://www.cnblogs.com/highend/archive/2011/08/04/aspnet_mvc3_controller_and_view.html