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

    八,构件Form表单

     

      1.Html.BeginForm()

          该方法用于构建一个From表单的开始,他的构造方法为:

          Html.BeginForm("ActionName","ControllerName",FormMethod.method)

          一般构建一个表单结构如下

         <% using(Html.BeginForm ("index","home",FormMethod.Post)){ %> 

          。。。。。。

         <%} %>

          他将在客户端产生一个类似<form action="/account/login" method="post"></form>标签

       

        2.现在开始创建一个表单实例,首先在Index.aspx中构建一个表单

      <% using(Html.BeginForm ("index","home",FormMethod.Post)){ %> 
     帐号:<%=Html .TextBox ("username") %>
     <br/>
     密码:<%=Html .Password ("password") %>
     <br />
     <input type="submit" value="登录" />
     <%} %>

        3.在对应得控制器HomeController.cs中写入下面代码,传递出一个ViewData[]字典:

    public ActionResult Index()
            {
                string struser = Request.Form["username"];
                string strpass = Request.Form["password"];
                ViewData["w"] = "你的账号是:" + struser + "你的密码是:" + strpass;
                return View();
            }

        4.在Index.aspx中写接受传值

        <%=ViewData ["w"] %>

         5。运行效果如下


    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/mane_yao/archive/2010/07/07/5719142.aspx

  • 相关阅读:
    02方法 课后作业1
    HDU 1518
    POJ 2406
    HDU 1953
    HDU 1272
    POJ -- 3842
    POJ -- 3233 求“等比矩阵”前n(n <=10^9)项和
    POJ ---3070 (矩阵乘法求Fibonacci 数列)
    POJ --- 3613 (K步最短路+矩阵快速幂+floyd)
    POJ --- 2918 求解数独
  • 原文地址:https://www.cnblogs.com/mane/p/1830091.html
Copyright © 2011-2022 走看看