Action重定向总结
[HttpPost]
public ActionResult StudentList( string StudName, string studName, DateTime BirthDay, FormCollection form, string controller, string Action, StudentModels student)
{
//其中StudName为aspx页面中标签的name属性(StudName不区分大小写)
//其中BirthDay为页面中标签的name属性(类型可自己指定【需转换成功才可以】,这里为DateTime)同样BirthDay不区分大小写
//其中controller,Action为路由信息(controller,Action不区分大小写)
//FormCollection包含了post回来的信息 通过form[]来取值
//如果使用强类型绑定 可通过实体回传值 这里实体为StudentModels
//同样可以使用Request.Form[] Request.QueryString[] Request[] 来取值 不过此Request非WebForm中的Request 这里的Request是RequestBase抽象类的实例 WebForm中Request是封装类 HttpRequest的实例 #region 到要经过执行controller里方法后 显示出页面。
//return RedirectToAction("Index");//可跳出本controller
//return RedirectToRoute(new {controller="Home",action="Index"});//可跳出本controller
//Response.Redirect("Index");//只能使用本controller下的方法名称。返回值为void
//return Redirect("Index");//只能使用本controller下的方法名称。
#endregion #region 直接显示出对应的页面 不经过执行controller的方法。
//return View("Index");//被controller 的其他视图//return View("~/Views/Home/Index.aspx");//任意controller下的其他视图
#endregion
return View();
}
//重定向跳转 到指定视图
//1. 使用视图名称创建一个呈现视图的 System.Web.Mvc.ViewResult 对象。(不经过Action 方法)
return View("RedirectOne");
return View("~/Views/Two/RedirectOne.cshtml"); //重定向跳转 到本controller下的action
return Redirect("RedirectOne");
Response.Redirect("RedirectOne");
return null; //重定向跳转 到其他或本controller下的action
//本controller
return RedirectToAction("RedirectOne");
//其他controller
return RedirectToAction("MasterOne", "One");
//本controller
return RedirectToRoute(new { action = "RedirectOne" });
//其他controller
return RedirectToRoute(new { controller = "One", action = "MasterOne" });
//跨区域 重定向
//其他controller
return RedirectToAction("Index", "BlogIndex", new { area="Blog"});
return RedirectToRoute( new { area = "Blog" ,controller="BlogIndex",action="Index"});
4.加载其他视图的方式
//返回 其他的视图,不经过controller
//可以 传递 model 参数
public PartialViewResult PartialTwo()
{
List<string> list = new List<string>() {
"姓名",
"密码"
};
return PartialView(); return PartialView("PartialOne", list);//本controller 下的视图,带参数 return PartialView("~/Views/Redirect/PartialOne.cshtml", list);//其他controller 下的视图 带参数 return PartialView("~/Views/LayoutOne/PageOne.cshtml");//其他controller 下的视图
}
Action重定向总结的更多相关文章
- struts2 action重定向
struts2的结果类型: <action name="loginAction" class="com.itheima.action.LoginAction&quo ...
- ASP.Net MVC Action重定向跳出Controller和Area
1.重定向方法简介 [HttpPost] public ActionResult StudentList( string StudName, string studName, DateTime Bir ...
- struts2 action重定向action中文乱码处理
比如:Action方法productCategorySave()变量message,传递给Action方法productCategoryAdd(),当变量message为中文变量时,要进行编码设置,不 ...
- Asp.net Mvc Action重定向总结
摘自博客园 程晓晖 [HttpPost] public ActionResult StudentList( string StudName, string studName, DateT ...
- Struts1 action重定向跳转 带参数
ActionForward forward = new ActionForward("kmRentalMain.do?method=view&fdId="+id);forw ...
- 20SpringMvc_结果的转发可共享参数;重定向不能共享参数
Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE MicrosoftInternetExplorer4 /* Style Definiti ...
- struts2视频学习笔记 03-06(Struts 2配置文件无提示问题,Action配置中的各项默认值,各种转发类型)
课时3 解决Struts 2配置文件无提示问题(eclipse):window→preference→XML→XML Catlog
- Struts2之Action接收请求参数和拦截器
技术分析之在Struts2框架中使用Servlet的API 1. 在Action类中也可以获取到Servlet一些常用的API * 需求:提供JSP的表单页面的数据,在Ac ...
- Struts2中Action之ResultType
我们在struts-defalut.xml文件中可以看到如下图所示: 这些类型是配置文件所带的.接下来我们主要讲解我标注出来的这个,其他的我就不做详解了,有兴趣的可以去试试. web.xml文件我在这 ...
随机推荐
- 安装Node.js
1.window下安装Node.js 安装git,方便使用命令行. 网址:http://www.git-scm.com/download/ 下载后直接安装即可 接着安装Node.js https:// ...
- HTML5 Canvas前台压缩图片并上传到服务器
1.前台代码: <input id="fileOne" type="file" /> <input id="btnOne" ...
- 回顾:Linq To SQL语法 - 实体类
第一篇博客,还望各位大神勿喷 小弟在此代码奉上........ 借用NorthWind数据库,实现一个商品展示的小功能.上代码: 添加对Linq的引用 using System.Data.Linq;/ ...
- QT-Demo-Colck-01
QT += widgets QT += core HEADERS += \ mainwindow.h SOURCES += \ mainwindow.cpp \ main.cpp #ifndef MA ...
- 《Hadoop权威》学习笔记四:Hadoop的I/O
一.数据完整性 二.压缩 三.序列化 基本概念 序列化指的是将结构化对象转化为字节流以便于通过网络进行传输或写入持久化存储的过程 反序列化指的是将字节流转为一系列结构化对象的过程. 进程间通信 ...
- mysql在linux的安装
- Kendo Web UI Grid添加一个html控件如(checkbox,button)
在Kendo Web UI Grid增加一个控件如效果图: <div id="grid1"></div><script> $("#gr ...
- [Mugeda HTML5技术教程之2] Mugeda HTML5富媒体平台简介
[Mugeda HTML5技术教程之2] Mugeda HTML5动画平台简介 摘要:Mugeda提供基于云的平台,供开发人员和设计人员快速的开发.发布和统计基于HTML5的,包含丰富动画和交互的移动 ...
- Python 基础教程中的问题及解决方案(1)
1. 在ubuntu中,调用终端时如: f = open('/home/theone/test_input.txt', 'r') 中的txt格式文本不能加后缀 正确的应为: f = open('/h ...
- HTML5面试题-备
万不可投机取巧.只求当时过关,非长久之计也!(感谢大神分享) 面试有几点需要注意: 面试题目: 根据你的等级和职位变化,入门级到专家级:范围↑.深度↑.方向↑. 题目类型: 技术视野.项目细节.理论知 ...