使用jQuery UI Dialog动态生成一个对话框,使用jQuery.validate是实现验证。
MVC Control代码:
public ActionResult Create()
{
return PartialView();
}
MVC View代码
@model NetworkGrain.Models.Action
<form method="post" id="create" action="">
<dl>
<dt>编号:</dt>
<dd><input id="A_ID" name="A_ID" type="text" class="required" /></dd>
<dt>标题:</dt>
<dd><input id="A_Caption" name="A_Caption" type="password" class="required" /></dd>
<dt>控制器:</dt>
<dd><input id="A_Control" name="A_Control" type="text" class="required" /></dd>
<dt>父编号:</dt>
<dd><input id="P_ID" name="P_ID" type="text" class="required" /></dd>
<dt>停用:</dt>
<dd><input id="A_Status" name="A_Status" type="checkbox" class="required" /></dd>
<dt>说明:</dt>
<dd><input id="A_Comment" name="A_Comment" type="text" class="required" /></dd>
<dd>@Html.ValidationSummary(true, "创建失败,请更正错误并重试。")</dd>
</dl>
</form>
javascript代码
$.ajax({
type: "GET",
url: "/Action/Create",
cache: false,
global: false,
success: function (data) {
var dlg = $(data);
dlg.dialog({
title: "添加权限",
modal: true,
buttons: {
"确定": function () {
if ($("#create").validate().form() == true) { //手动验证
alert("OK");
}
},
"关闭": function () {
$(this).dialog("close");
}
}
});
}
});