zoukankan      html  css  js  c++  java
  • mvc表单Form提交 --实体

    1、方式1:字段加验证  

    • @model MvcWeb.Models.UserInfo  
    • @{  
    •     ViewBag.Title = "Add";  
    • }  
    •   
    • <h2>Add</h2>  
    • @using (Html.BeginForm())  
    • {  
    •     @Html.ValidationSummary(true)  
    •   
    •     @Html.HiddenFor(model => model.Id)  
    •   
    •     <div class="editor-label">  
    •         @Html.LabelFor(model => model.UserName)  
    •     </div>  
    •     <div class="editor-field">  
    •         @Html.EditorFor(model => model.UserName)  
    •         @Html.ValidationMessageFor(model => model.UserName)  
    •     </div>  
    •   
    •     <p>  
    •         <input type="submit" value="Save" />  
    •     </p>  
    • }  
    • ==============================================  
    • 2、方式2  
    • @{  
    •     ViewBag.Title = "Add";  
    • }  
    •   
    • <h2>Add</h2>  
    • @using (Html.BeginForm("Add", "UserInfo", FormMethod.Post)) //方法名称,控制器名称  
    • {  
    •     <table>  
    •     <tr>  
    •         <td>  
    •             用户名称:  
    •         </td>  
    •         <td>  
    •             @Html.TextBox("txtUserName")  
    •         </td>  
    •     </tr>  
    •     <tr>  
    •         <td>  
    •             密码:  
    •         </td>  
    •         <td>  
    •              @Html.TextBox("txtPassword", ViewData["url"])  
    •         </td>  
    •     </tr>  
    •     <tr>  
    •         <td>  
    •             <input id="Submit1" type="submit" value="submit" />  
    •         </td>  
    •         <td>  
    •             <input id="Reset1" type="reset" value="reset" />  
    •         </td>  
    •     </tr>  
    • </table>  
    • }  

    ----------------------

    <%using (Html.BeginForm("Create", "Book")) { %>
            <div>

    //这里是你要提交的表单信息
            <div>
                <input type="submit" id="submit" name="submit" value="搜索" />
            </div>
            <%} %>

    如果html表单中不使用@Html控件,直接写html控件,那么控制器中,要通过 FormCollection form: form["txtAccount"];  取值          

    public ActionResult UserRegister(FormCollection form)         {             RegisterModel reg = new RegisterModel();             reg.Account = form["txtAccount"];             if (form["txtAccount"]!="huika123")             {

                }             return View();         }

  • 相关阅读:
    Android 的快速增长让一些开发人员担忧 狼人:
    Android程序开发入门教程 狼人:
    2010:Android 商机之年 狼人:
    控制力的较量 Android上的博弈 狼人:
    深度解析Windows Phone 7 开发 狼人:
    图解iPhone开发入门教程 狼人:
    用Android LiveCD体验Android 操作系统的魅力 狼人:
    Android 教程之实现动作感应技术 狼人:
    Android版多功能日历,欢迎大家测试 狼人:
    iPhone、Windows Mobile、Symbian、Android移动开发前景分析 狼人:
  • 原文地址:https://www.cnblogs.com/DTWolf/p/4615277.html
Copyright © 2011-2022 走看看