我想创建一个简单的表单,使用
JQ模式
.
查看/Home/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输入了不正确的值并单击“保存”按钮,我不想关闭窗体。我想显示一个错误消息,就像使用
验证摘要
在正常视图上。