MVC表单提交加JS验证

做一个普通表单提交,但是要加前端验证,如下:

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;

}

posted @ 2016-01-26 14:05  蜡笔~小新  阅读(841)  评论(0)    收藏  举报