1. MVC 路由
  2. 重定向
  3. 问题记录
1)MVC 路由
入口方法:
(Global.asax)Application_Start()--->(App_Start/RouteConfig.cs)RegisterRoutes()--->(Controllers/)Controller--->(Views/)Action--->(Views/Action/)View
其中Application_Start()代码如下:
<span style="font-size:14px;font-weight: normal;"><span style="font-size:14px;">namespace MvcAspxMovie
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute(
name: "Default",//路由名称
url: "{controller}/{action}/{id}",//带有参数的URL
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }//默认参数
);
}
}
}</span></span>

2)重定向:页面跳转传参(RedirectToAction())

在MVC中页面后台中常用的页面跳转方法有几种,如:return View()、return RedirectToAction().
  一般情况下我们返回的都是本页面,所以使用return View()就够了.有时候我们也会遇到返回的页面不是本页面的,就要用到return
RedirectToAction();方法了。
举例如下,通过RedirectToAction调用跳转到HelloWorld(),页面返回“helloworld”。
        public string HelloWorld()
{
return "hello world";
}
public ActionResult TestRedirect()
{
return RedirectToAction("HelloWorld");
}
遇到需要传参的情况,则需要对RedirectToAciton()扩展
RedirectToAction(string ActionName);  //<span style="font-family: Arial; font-size: 14px; line-height: 26px;">跳转到同一Controller 里面的不同Action</span>
RedirectToAction(string ActionName, object viewData); //<span style="font-family: Arial; font-size: 14px; line-height: 26px;">跳转到同一Controller 里面的不同Action,含参数</span>
RedirectToAction(string ActionName, string ControllerName); //<span style="font-family: Arial; font-size: 14px; line-height: 26px;">跳转到不同Controller 里面的不同Action</span>
RedirectToAction(string ActionName, string ControllerName, object viewData); //<span style="font-family: Arial; font-size: 14px; line-height: 26px;">跳转到不同Controller 里面的不同Action,含参数</span>
<span style="font-family: Arial; font-size: 14px; line-height: 26px;"><span style="font-family: Arial; font-size: 14px; line-height: 26px;">如:RedirectToAction("Index","Home",new {msg="操作成功",name="admin"});</span>
</span>
<%: Html.ActionLink("Edit", "Edit", new { id=item.ID }) %> 

举例如下,调用TestRedirect()最终页面返回“hello bailang”

        public string HelloWorld(string str)
{
return "hello "+str;
}
public ActionResult TestRedirect()
{
return RedirectToAction("HelloWorld",new{str="bailang"});
}

3)问题记录

20160104 初学MVC 遇到新建一个controller,默认action
是index,URL输入 http://localhost:15683/TestThumbnail 默认为http://localhost:15683/TestThumbnail/index,但未知修改会造成再次URL输入默认到index不起作用,必须定位输入http://localhost:15683/TestThumbnail/index,原因发现为:在根目录下生成同名controller的目录。
解决方法:删除该目录即可。

MVC2: 路由 及 遇到问题记录的更多相关文章

  1. nginx 配置路由规则转发配置记录

    工作中公司要求针对经销商PC端和工厂PC端的访问地址固定访问. 经销商PC端 http://localhost/ 工厂PC端   http://localhost/fac 文件磁盘路径: /crm/n ...

  2. Vue.js中,如何自己维护路由跳转记录?

    在Vue的项目中,如果我们想要做返回.回退操作时,一般会调用router.go(n)这个api,但是实际操作中,使用这个api有风险,就是会让用户跳出当前应用,因为它记录的是浏览器的访问记录,而不是你 ...

  3. GNS3 模拟icmp记录路由

    路由配置: icmp记录路由抓取出接口的IP地址,最多可以抓取9个.ip协议头中的options为40个字节 R1 : conf t int f0/0 no shutdown ip add 192.1 ...

  4. RouterOS DNS劫持 -- A记录

    通常我们使用RouterOS的DNS主要是用于实现DNS缓存功能,即由RouterOS实现DNS服务器解析功能,除了这个功能,RouterOS可以实现对内网域名解析劫持,即实现路由网关的A记录查询. ...

  5. ip route rule 路由策略 高级路由 捆绑 网桥

    http://lwfs.net/2005/11/28/10/ #!/bin/bash IP0= IP1= GW0= GW1= NET0= NET1= DEV0=eth0 DEV1=eth1 # com ...

  6. AngularJS路由系列(2)--刷新、查看路由,路由事件和URL格式,获取路由参数,路由的Resolve

    本系列探寻AngularJS的路由机制,在WebStorm下开发.主要包括: ● 刷新路由● 查看当前路由以及所有路由● 路由触发事件● 获取路由参数 ● 路由的resolve属性● 路由URL格式 ...

  7. DNS记录

    转载于:https://www.cnblogs.com/sddai/p/5703394.html 类型 SOA NS A AAAA PTR CNAME MX --------------------- ...

  8. Dubbo 系列(07-2)集群容错 - 服务路由

    目录 Dubbo 系列(07-2)集群容错 - 服务路由 1. 背景介绍 1.1 继承体系 1.2 SPI 2. 源码分析 2.1 创建路由规则 2.2 RouteChain 2.3 条件路由 Dub ...

  9. Vue——路由回退至指定页面

    先来引出一下遇到的问题:在做一个移动端支付页面,在付款页面点击支付按钮,支付失败时跳转至支付失败提示页面:支付成功时跳转至支付成功页面.在支付成功页面下,如果用户点击手机自带的“返回”键,就又会跳转至 ...

随机推荐

  1. mybatis报错(三)报错Result Maps collection does not contain value for java.lang.Integer解决方法

    转自:https://blog.csdn.net/zengdeqing2012/article/details/50978682 1 [WARN ] 2016-03-25 13:03:23,955 - ...

  2. python multiprocessing模块

    python multiprocessing模块 原文地址 multiprocessing multiprocessing支持子进程.通信和共享数据.执行不同形式的同步,提供了Process.Queu ...

  3. 009-流程控制 for 语句

    流程控制 for 语句 ##################### 语法一 ################################# #!/bin/bash do echo $i done ...

  4. 最小可观(Minimal Observability Problem in Conjunctive Boolean Networks)

    论文链接 1. 什么是 conjunctive Boolean network (CBN) 仅仅包含and运算. 下面这个式子为恒定更新函数 2. 什么是可观 定义在时刻k是CBN的状态为 X(k) ...

  5. python3:类和实例

    面向对象最重要的概念就是类(Class)和实例(Instance),必须牢记类是抽象的模板,比如Student类,而实例是根据类创建出来的一个个具体的“对象”,每个对象都拥有相同的方法,但各自的数据可 ...

  6. Sublime3 配置node.js 环境 The process "node.exe" not found

    配置中文显示调试结果 [下载地址](https://github.com/tanepiper/SublimeText-Nodejs) 1. 到上述地址下载压缩文件 2.将文件解压到sublime的插件 ...

  7. <转> thinkPHP的常用配置项2

    'URL_PATHINFO_DEPR'=>'-',//修改URL的分隔符'TMPL_L_DELIM'=>'<{', //修改左定界符'TMPL_R_DELIM'=>'}> ...

  8. oracle中用case when查询列表

    查询sql语句如下 SELECT * FROM ( SELECT * ,ROW_NUMBER() OVER ( PARTITION BY scene_code ORDER BY (CASE statu ...

  9. Python中的网络扫描大杀器Scapy初探

    Python中的网络扫描大杀器Scapy初探     最近经历了Twisted的打击,这个网络编程实在看不懂,都摸不透它的内在逻辑,看来网络编程不是那么好弄的.还好,看到了scapy,这种网络的大杀器 ...

  10. 最简单的注册美区Apple ID方法

    最简单方法注册苹果美区Apple ID 1.打开苹果官网链接 苹果官网 2. 点击右下角的 United States 3. 点击图片中的选项 4.点击右上角的选项创建新的Apple ID 注意是新的 ...