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. Ajax请求后台数据

    一.前期准备 安装好XAMPP软件,并运行起来.本文代码是基于XAMPP开发环境,XAMPP是完全免费且易于安装的Apache发行版,其中包含MariaDB.PHP和Perl.XAMPP开放源码包的设 ...

  2. 4-2如何判断字符串a是否以字符串b开头或结尾

    1.相关介绍 1.1修改文件权限和查看文件权限 在windows平台实验时 os.chmod()无法将文件权限修改为可执行,暂不深究如何实现.在linux平台进行测试. (1)创建三个文件 pytho ...

  3. 方法签名_spring aop_around

    //注解签名 方法签名 Signature signature = pjp.getSignature(); MethodSignature methodSignature= (MethodSignat ...

  4. Eclipse Git分支实战

    切换分支 右键工程,创建新分支 命名新分支 点击finish,可以看到项目已经切换到hot_fix 修改代码: Ctrl+#提交到本地仓库,之后提交到远程仓库 Next,Finish 等待一下, 点击 ...

  5. SVN更新报错:Checksum mismatch for 解决办法

    问题: Checksum mismatch while updating '……'; expected: '3f9fd4dd7d1a0304d8020f73300a3e07', actual: 'cd ...

  6. vue + nginx部署404

    记录: vue项目打包放到服务器,使用nginx反向代理的时候路由页面刷新报404,因为刷新时,不存在路径对应的文件或文件夹,需要在nginx配置中添加代码: index index.html; tr ...

  7. IsDate(expression)函数

    IsDate 函数 返回 Boolean 值指明某表达式是否可以转换为日期. IsDate(expression) expression 参数可以是任意可被识别为日期和时间的日期表达式或字符串表达式. ...

  8. Codeforces Round #573 (Div. 2) E. Tokitsukaze and Duel (博弈)

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. jquery.fancybox.js 解决只加载一次的问题

    问题描述:有一块图片区域,页面第一次加载的时候jQuery(".fancybox-button").fancybox({}); 使用ajax上传成功后显示在图片区域,再次jQuer ...

  10. java:Conllection中的List,ArrayList添加元素,删除元素,输出元素

    java:Conllection中的List,ArrayList添加元素,删除元素,输出元素 //为list接口实例化 List<String> addlist = new ArrayLi ...