2

我想创建一个简单的表单来使用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 输入不正确的值并单击保存按钮,我不想关闭表单。我想在普通视图上使用验证摘要时显示一条错误消息。

谢谢!

4

1 回答 1

0

查看jQuery 验证插件或使用MVC 模型验证来自动生成 JS。它在模态对话框中的事实应该对这些技术没有影响。

于 2010-07-27T14:11:05.733 回答