MVC Form管理の簡単な表
1783 ワード
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; }
}