view添加表单
<div id="divForm"> @using (Html.BeginForm("AddOrUpdateTest", "ControllerName", FormMethod.Post, new { id = "formId", @class = "" })) { @Html.AntiForgeryToken() <table> <tr style="display:none;"> <td><label>编号:</label></td> <td><input id="ID" name="ID" type="text" /></td> </tr> <tr> <td><label>名称:</label></td> <td><input id="Name" name="Name" type="text" /></td> </tr> </table> <div align="center"> <a href="#" class=""><span onclick=" AddOrUpdateSubmit() ">确定</span></a> <a href="#" class=""><span onclick=" Clear() ">取消</span></a> </div> } </div>
view 添加获取方法
function AddOrUpdateSubmit() { //可添加验证条件后再提交 $("#formId").submit(); } function Clear() { $("#ID").val(""); $("#Name").val(""); }
controller(ControllerName)中添加方法AddOrUpdateTest()
[HttpPost] public ActionResult AddOrUpdateTest(TestClass test) { int result = 0; //处理数据到数据库 //这里用session记录处理结果 Session["Result"] = result; return RedirectToAction("Index", "ControllerName"); }
model中有类TestClass
public class TestClass { public int ID{ get; set; } public string Name{ get; set; } }
本文出自 “11018335” 博客,请务必保留此出处http://11028335.blog.51cto.com/11018335/1732601
原文地址:http://11028335.blog.51cto.com/11018335/1732601