我正在使用ASP .NET来显示一个包含几个输入字段的JQuery对话框.我现在需要将这些字段提交给一个操作方法,就像普通的HTML提交按钮在ASP .NET MVC应用程序上的工作方式一样.我该如何做到这一点?
所有的表单字段是必需的.
<%Html.BeginForm("AddUser", "User"); %>
<fieldset>
<label for="name">Name</label>
<input type="text" name="name" id="name" />
<label for="email">Email</label>
<input type="text" name="email" id="email" value="" />
<label for="password">Password</label>
<input type="password" name="password" id="password" value="" />
</fieldset>
<%Html.EndForm(); %>
Run Code Online (Sandbox Code Playgroud)
"
$(function() {
$("#dialog").dialog({
bgiframe: true,
height: 400,
width: 600,
modal: true,
buttons: {
'Create user account': function() {
$(this).dialog('close');
},
Cancel: function() {
$(this).dialog('close');
}
}
});
});
在提交表单的代码中添加一行:
$(function() {
$("#dialog").dialog({
bgiframe: true,
height: 400,
width: 600,
modal: true,
buttons:
{
'Create user account': function() {
$('#yourDialogFormID').submit(); // add this line
$(this).dialog('close');
},
Cancel: function() {
$(this).dialog('close');
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
您可以通过为Html.BeginForm()方法提供参数来设置ID htmlAttributes(object如果我正确记住结构,则键入类型- 在IntelliSense中的重载方法中查找它).