zoukankan      html  css  js  c++  java
  • 使用Html.BeginForm来提交表单

    https://www.cnblogs.com/m2345/p/5361529.html

     

    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"] %>
  • 相关阅读:
    [bzoj4893]项链分赃
    [Spoj]Counting Divisors (cube)
    [Noi2016]国王饮水记
    [Noi2016]网格
    [Noi2016]优秀的拆分
    [Noi2016]区间
    [Noi2015]寿司晚宴
    Codeforces Round #411 (Div. 2)
    VK-Cup2017 Wild Card Round 2
    [Noi2015]小园丁和老司机
  • 原文地址:https://www.cnblogs.com/wfy680/p/14280603.html
Copyright © 2011-2022 走看看