zoukankan      html  css  js  c++  java
  • ASP.NET MVC中如何实现页面跳转

    1,最简单的方式:超链接

    以下分别是连接到HomeController控制器下的SharpL动作方法,以及百度首页。代码如下:

    1 <a href="HomeSharpL">打开SharpL</a>
    1 <a href="http://www.baidu.com">打开百度</a>

     并且可以向url中添加参数,传递到Action中,代码如下:

    复制代码
    1 --前台
    2 <a href="/Href/HrefTest?City=北京&Name=SharpL&Age=18">点击我,返回给你一个字符串</a>
    3 //后台
    4         public string HrefTest()
    5         {
    6             var stu = new Stu();
    7             this.UpdateModel(stu);
    8             return  string.Format("{0}{1}岁,来自{2}", stu.Name, stu.Age, stu.City);
    9         }
    复制代码

    或者是使用HTML辅助器生成<a>元素,代码如下:

    1     @Html.ActionLink("nihao", "Here")

    注:虽然在《精通ASP.NET MVC4》书中有大量的用HTML辅助器方法的使用,但是在实际的项目中我们很少这样去用,在生产过程中,会由设计和前端设计好页面后,程序员进行套版即可,而用上述代码的方式,是不利于套版的,不够直观,无法确定ID和Class,不能很好的使用css样式。

    2,window.location。

    完成当前页面的业务规则后,关闭当前的页面,并打开指定的页面,代码如下:

    1         $("#btnBaidu").click(function () {
    2             window.location = "http://www.baidu.com";
    3         });

    点击按钮后,跳转到百度首页。

    也可以跳转到指定的控制器,代码如下:

     window.location='/Home/Thanks'

    再见。

    出处:http://www.cnblogs.com/SharpL/p/4675594.html

  • 相关阅读:
    hibernate08--OpenSessionInView
    hibernate07--关联映射
    hibernate06--参数的绑定
    hibernate05--list和iterator
    hibernate04--三种状态之间的转换
    hibernate03增删改查
    hibernate02环境的搭建
    hibernate01ORM的引入
    mongoDB
    spring-boot(三) HowTo
  • 原文地址:https://www.cnblogs.com/mq0036/p/9082547.html
Copyright © 2011-2022 走看看