【问题标题】:jqModal and ASP.NET MVCjqModal 和 ASP.NET MVC
【发布时间】: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


    【解决方案1】:

    查看jQuery validation plugin 或使用MVC Model Validation 自动生成JS。它在模态对话框中的事实应该对这些技术没有影响。

    【讨论】:

    • 当我单击模态对话框上的保存按钮时,我输入 if(!ModelState.IsValid) 并调用返回 View("AddProduct", product)。之后,模态对话框关闭,我想阻止它。
    • 关于提交按钮...我忘了包含“MicrosoftAjax.js”和“MicrosoftMvcAjax.js”脚本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    • 1970-01-01
    • 2010-10-10
    • 2016-05-17
    • 2020-11-25
    • 2010-09-11
    相关资源
    最近更新 更多