mvc表单Form提交
来源:互联网 发布:网络视频会议系统 编辑:程序博客网 时间:2024/06/08 07:09
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>}