she*_*nyL 3 validation jquery-dialog asp.net-mvc-3
我使用jquery对话框显示了很多表单,我希望在其上添加客户端验证.我通读了一些例子,说mvc 3已经以某种方式支持jquery客户端验证,但我尝试了包含必要的脚本,我的表单如下:
@using (Html.BeginForm("CreateFood", "Home", FormMethod.Post, new { id = "formData" }))
{
@Html.ValidationSummary(false, "Please fix these errors.")
Run Code Online (Sandbox Code Playgroud)
当我尝试提交我的表格而没有填写必填字段时,我仍然会得到任何消息.谁能给我更多的想法/解释/例子?
真的需要帮助...谢谢......
更新(在我的对话框的脚本中添加)
$createdialog.dialog("option", "buttons", {
"Cancel": function () {
//alert('Cancel');
$createdialog.dialog('close');
},
"Submit": function () {
var frm = $('#formData');
$.ajax({
url: '/Food/CreateFood',
type: 'POST',
data: frm.serialize(),
success: $createdialog.dialog('close')
});
}
});
Run Code Online (Sandbox Code Playgroud)
删除后,打开对话框:
// Once drop, open dialog to create food
options.drop = function (event, ui) {
// Get the ContainerImgName which food dropped at
var cimg = $(this).attr('id');
// Pass in ContainerImgName to retrieve respective ContainerID
// Once success, set the container hidden field value in the FoodForm
$.ajax({
url: '/food/getcontainerid',
type: 'GET',
data: { cImg: cimg },
success: function (result) { $('#containerID').val(result); }
});
clear();
$.validator.unobtrusive.parse($createdialog);
$createdialog.dialog('open');
};
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题,解决了:
$(name).dialog({
autoOpen: true,
width: options.witdth,
heigth: options.height,
resizable: true,
draggable: true,
title: options.title,
modal: true,
open: function (event, ui) {
// Enable validation for unobtrusive stuffs
$(this).load(options.url, function () {
var $jQval = $.validator;
$jQval.unobtrusive.parse($(this));
});
}
});
Run Code Online (Sandbox Code Playgroud)
当然你可以在对话框的关闭事件上添加验证,取决于你正在做什么,在我的情况下,弹出窗口只是为了显示错误,所以我已经对内容的加载进行了验证.(这个弹出窗口显示的是Action结果)
归档时间: |
|
查看次数: |
6206 次 |
最近记录: |