我想创建一个简单的表单来使用jqModal添加新产品。
查看/主页/Index.aspx:
<script type="text/javascript">
$(document).ready(function () {
$('#addProductControlSection').jqm({ modal: true,
ajax: '<%: Url.Action("AddProduct", "Home") %>',
onHide: myAddClose
});
function myAddClose(hash) {
hash.w.fadeOut('1000', function () { hash.o.remove(); });
}
});
</script>
// rest of the code...
<a href="#" class="jqModal">Add product</a>
<div id="addProductControlSection" class="jqmWindow">
</div>
家庭控制器:
public ActionResult AddProduct()
{
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AddProduct(Product product)
{
if(!ModelState.IsValid)
{
// how to show an error?
}
_productRepository.Save(product);
// how to display 'success' or something...
}
我不知道如何实现验证。如果用户为 Product.Price 输入不正确的值并单击保存按钮,我不想关闭表单。我想在普通视图上使用验证摘要时显示一条错误消息。
谢谢!