zoukankan      html  css  js  c++  java
  • MVC入门学习笔记(八)

    七.MVC中的QueryString传值

        MVC中的QueryString传值和普通传值方式是一样的,它同样需要再代码逻辑中获取字符串的值,并在页面中显示,以往asp.net是在.cs文件中获取字符串的值,然后再页面.aspx中进行显示如下:

       代码: Default.aspx

     <%@ Page Title="主页" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
     CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <a  href ="About.aspx?id=12345">hello</a>
        </asp:Content>

     

               About.aspx

    <%@ Page Title="关于我们" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
        CodeBehind="About.aspx.cs" Inherits="WebApplication1.About" %>

    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    </asp:Content>

              About.aspx。cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace WebApplication1
    {
        public partial class About : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                Label1.Text = Request.QueryString["id"];
            }
        }
    }


    在MVC中的传值思想也是这样的

        1.相对于上面,我们在Index.aspx中写入一个QueryString字段,其中new{word="Qstring"}就是定义的字段(注意:只能用word关键字)

       <%=Html.ActionLink("链接", "about", "home",

               new { word = "Qstring" },

               new { @Class="x"}  

        )%>

         2.在控制器HomeController.cs中写入获取字符串,需要再About()方法中获取Index.aspx传递过来的字段

        public ActionResult About()
            {
                ViewData["w"] = Request.QueryString["word"];
                return View();
            }

         3.在About.aspx中接收ViewData[]字典

         <%=ViewData ["w"] %>

         4。运行效果

  • 相关阅读:
    link标签中的integrity和crossorigin字段
    jquery中的插件EChars的使用
    php函数 截断字符
    子元素脱离文档标准流,父元素没有高度解决办法
    有序无序Ul->Li Ol->Li菜单,默认点击当前弹出下拉,再次点击收起下拉菜单(变形2 ---修饰)
    有序无序ul->li ol->li菜单,默认点击当前弹出下拉,再次点击收起下拉菜单
    bootstrap使用总结(carousel设置大小。item设置大小,img设置大小)
    bootstrap使用总结(导航在carousel居中之上)
    html中设置height=100%无效的问题
    第四次上机课
  • 原文地址:https://www.cnblogs.com/mane/p/1830088.html
Copyright © 2011-2022 走看看