view添加表单

<divid="divForm">@using(Html.BeginForm("AddOrUpdateTest","ControllerName",FormMethod.Post,new{id="formId",@class=""})){@Html.AntiForgeryToken()<table><tr><td><label>编号:</label></td><td><inputid="ID"name="ID"type="text"/></td></tr><tr><td><label>名称:</label></td><td><inputid="Name"name="Name"type="text"/></td></tr></table><divalign="center"><ahref="#"class=""><spanonclick="AddOrUpdateSubmit()">确定</span></a><ahref="#"class=""><spanonclick="Clear()">取消</span></a></div>}</div>

view添加获取方法

functionAddOrUpdateSubmit(){//可添加验证条件后再提交$("#formId").submit();}functionClear(){$("#ID").val("");$("#Name").val("");}

controller(ControllerName)中添加方法AddOrUpdateTest()

[HttpPost]publicActionResultAddOrUpdateTest(TestClasstest){intresult=0;//处理数据到数据库//这里用session记录处理结果Session["Result"]=result;returnRedirectToAction("Index","ControllerName");}

model中有类TestClass

publicclassTestClass{publicintID{get;set;}publicstringName{get;set;}}