【发布时间】:2010-07-27 14:04:44
【问题描述】:
我想创建一个简单的表单来使用 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>
HomeController:
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 输入不正确的值并单击保存按钮,我不想关闭表单。我想在普通视图上使用 Validation Summary 时显示一条错误消息。
谢谢!
【问题讨论】:
标签: asp.net-mvc jqmodal