一块儿学习MVC(4)Controllers的学习

   

   

   

  1. 控制器Controllers

    Controllers为控制器文档,AccountControllers内的方法对应View→Account下的cshtml文件。 html

    咱们看到AcountControllers中包含两个Login方法。Login()为进入Login.cshtml后读取的第一个方法。Login(string UserName,string PassWord)为处理HttpPost请求时所调用的方法(由于在方法上面加入了[HttpPost])。 web

    注:如想查看更多请单击System.Web.Mvc 命名空间 mvc

  2. 返回值

return RedirectToAction("Index"); spa

若是RedirectToAction(ActionName,ControllerName) htm

  

//一个参数时在本Controller下 blog

   

//能够直接跳到别的Controller. 文档

  

return RedirectToRoute(new {controller="Home",action="Index"});get

//可跳到其余controllerstring

Response.Redirect("Index");io

//适用于本controller下的方法名称。返回值为void

return Redirect("Index");

//适用于本controller下的方法名称。

return View("Index");

//直接显示对应的页面 不通过执行Controller的方法。

return View("~/Views/Home/Index.aspx");

//这种方法是写全路径,直接显示页面,不通过Controller方法

return View();

//直接显示页面,不通过Controller方法

相关文章
相关标签/搜索