做一个普通表单提交,但是要加前端验证,如下:
1. Action
public ActionResult Add(ProductModelproductID)
{
//operate…
}
[HttpPost]
public ActionResult Add(ProductModelmodel)
{
//operate…
}
2.View
@model ProductModel
@{
Layout = “~/Views/Shared/_Layout.cshtml”;
ViewBag.Title = “产品添加”;
}
<div class=”page-tl”>产品添加</div>
<div class=”pannel-info pannel-info-holiday”>
<form method=”post” action=”@Url.Action(“AddProduct”)” id=”addproduct” >
<div class=”holiday”>
<table>
<tr>
<th>产品名称</th>
<td>
@Html.TextBox(“ProductName”, Model.ProductName,)
</td>
</tr>
</table>
<div class=”holiday-manage-btn”>
<input type=”submit” id=”update” class=”btn-blue” value=”保存”>
<a class=”btn-white ” href=”@Url.Action(“Index”)”>取消</a>
</div>
</div>
</form>
</div>
@section foot{
<script src=”@Url.Content(JsSrcConfigurator.vacationProductJs)” type=”text/javascript”></script>
}
3.Javascripts
jQuery(function (j) {
jQuery(“#update”).click(function () {
return checkProduct();
})
})
function checkProduct()
{
var _productName = j(“#ProductName”).val();
if (!checkEmpty(_productName)) {
return false;
}
return true;
}