好的,我是一个完全的网络新手,但我必须承认我现在完全被迷住了。这是我的问题:
我有一个带有 MVCContrib 网格的页面和一个“添加帐户”链接,该链接会显示一个包装在 JQuery 对话框中的 Ajax 表单。当我第一次完成工作流程时,一切都很好。我可以通过 JQuery / Ajax 添加一个新项目并刷新网格(所以我认为)。但是,当我第二次尝试添加表单时,始终会提交第一个表单中的数据。我已经研究这个问题太久了,必须承认我完全被困住了。顺便说一句 - 我确定我这样做完全错误,所以请随时提出更好的建议。
这是表格:
@using (Ajax.BeginForm("SaveCheckAccount", "UserManagement", null, new AjaxOptions { OnSuccess = "onAccountAdded", OnFailure = "onAccountAddedFailed"}, new { id = "accountDetails" }))
{
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Id)
@Html.HiddenFor(model => model.version)
@Html.HiddenFor(model => model.User_Id)
@Html.HiddenFor(model => model.IsDefault)
<table>
<tr>
<td>
Account Number
</td>
<td>
@Html.TextBoxFor(model => model.AccountNumber)
@Html.ValidationMessageFor(model => model.AccountNumber, "*")
</td>
</tr>
<tr>
<td>
Routing Number
</td>
<td>
@Html.TextBoxFor(model => model.RoutingNumber)
@Html.ValidationMessageFor(model => model.RoutingNumber, "*")
</td>
</tr>
<tr>
<td>
Account Type
</td>
<td>
@Html.DropDownListFor(model => model.AccountType_Id, new SelectList(@accountTypes, "ID", "Name", Model.AccountType_Id))
@Html.ValidationMessageFor(model => model.CheckAccountType)
@Html.ValidationMessageFor(model => model.AccountType_Id, "*")
</td>
</tr>
<tr>
<td>
Bank Name
</td>
<td>
@Html.TextBoxFor(model => model.BankName)
@Html.ValidationMessageFor(model => model.BankName, "*")
</td>
</tr>
<tr>
<td>
Account Name
</td>
<td>
@Html.TextBoxFor(model => model.AccountName)
@Html.ValidationMessageFor(model => model.AccountName, "*")
</td>
</tr>
</table>
}
<script type="text/javascript">
$.ajaxSetup({ cache: false });
</script>
此 javascript 位于 bank.js 文件中
function BindCommands(createUrl) {
$("#modalAdd").live("click", function (e) {
var dialogBox = $("<div>");
e.preventDefault();
$(dialogBox).dialog({
autoOpen: false,
resizable: false,
title: 'Create Account',
modal: true,
show: { effect: "blind", duration: 50 },
hide: { effect: "blind", duration: 50 },
open: function (event, ui) {
$.ajax(
{
type: "Get",
url: createUrl,
success: function (result) {
$(dialogBox).html(result);
}
});
},
buttons: {
Save: function () {
$("#accountDetails").submit();
$(this).dialog('close');
},
Cancel: function () {
$(this).dialog("close");
}
}
});
$(dialogBox).dialog('open');
});
}
function onAccountAdded(data, status, xhr) {
$("#accounts-grid").html(data);
};
function onAccountAddedFailed(data, status, xhr) {
alert("Failed");
};
for 最初是通过单击此视图上的添加链接来呈现的:
<script type="text/javascript">
$.ajaxSetup({cache:false});
$(document).ready(function() {
var createUrl = '@Url.Action("NewBankAccountDetails", "UserManagement", new {userId=@Model.Id})';
BindCommands(createUrl);
});
</script>
@if (Model != null && Model.Id > 0)
{
<tr>
<td class="header" colspan="2">
User Accounts
</td>
</tr>
<tr>
<td>
<a href="#" id="modalAdd">Add Account</a>
</td>
</tr>
Html.RenderPartial("_BankAccountGrid", Model.CheckAccounts);
}