我試圖創建一種方式,以便在單擊提交按鈕或鏈接時,執行提交 並保持在相同的模式對話框中。 我的程序在同一個對話框中有兩種形式,一種是在第一種子程序出現之前不顯示,我希望在同一個對話框中提交第一個表單加載。如何在提交後保留模態對話框?
對於負載對話框我有這樣的代碼:
function loadDialog(tag, event, target) {
event.preventDefault();
var $loading = $('<img src="../../Content/assets/images/nivo-loader.gif" alt="loading" class="ui-loading-icon">');
var $url = $(tag).attr('href');
var $title = $(tag).attr('title');
var $dialog = $('<div></div>');
$dialog.empty();
$dialog
.append($loading)
.load($url)
.dialog({
autoOpen: false
, title: $title
, width: 600
, modal: true
, minHeight: 200
, show: 'fade'
, hide: 'fade'
});
});
然後在Create.cshtml:
@model Mvcproject.Models.MyModel
<script language="javascript" type="text/javascript">
$(function() {
$("input[type=submit]")
.button(
);
$('a.modalDlg2').live("click", function (event) { loadDialog('#modalDlg', event, '#Receipt Create'); });
/*$('input.Submit').live("click", function (event) {
e.preventDefault();
loadDialog('#modalDlg', event, '#Receipt Create');
});*/
$(".demo button").button({
icons:
{
primary: 'ui-icon-plusthick'
}
});
});
</script>
<h2>
Add line</h2>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset class="createReceipt">
<legend>User login</legend>
@if (ViewBag.Created)
{
<table class="createTable">
<tr>
<td rowspan="4">
<img src="../../Images/no_image.jpg" width="100" height="100" />
</td>
<th colspan="1">
@Html.LabelFor(model => model.User.Name)
</th>
<td colspan="5">
@Html.EditorFor(model => model.User.Name)
@Html.ValidationMessageFor(model => model.User.Name)
</td>
</tr>
<tr>
<th colspan="1">
@Html.LabelFor(model => model.User.Email)
</th>
<td colspan="5">
@Html.EditorFor(model => model.User.Email)
@Html.ValidationMessageFor(model => model.User.Email)
</td>
</tr>
<tr>
<th colspan="1">
@Html.LabelFor(model => model.User.Password)
</th>
<td colspan="5">
@Html.EditorFor(model => model.User.Password)
@Html.ValidationMessageFor(model => model.User.Password)
</td>
</tr>
<!--User picture-->
<tr>
<td>
<input type="file" value="browse" name="Browse" accept="image/gif, image/jpeg, image/jpg" />
</td>
</tr>
</table>
<p>
<input type="submit" class="Submit" value="Create" />
<buttonreceipt style="width: 150px; text-align: left">@Html.ActionLink("Create", "Create")</buttonreceipt>
</p>
}
else
{
<!-- This will be displayed when user data is submited and inserted into database-->
<table class="createTable">
<tr>
<th colspan="1">
@Html.LabelFor(model => model.User.Name)
</th>
<td colspan="5">
@Html.DisplayFor(model => model.User.Name)
</td>
</tr>
<tr>
<th colspan="1">
@Html.LabelFor(model => model.User.Email)
</th>
<td colspan="5">
@Html.DisplayFor(model => model.User.Email)
</td>
</tr>
<tr>
<td colspan="1">
<img src="@Model.User.Picture"/>
</td>
</tr>
</table>
}
</fieldset>
}
@if (!ViewBag.Created)
{
@Html.Partial("_AddUserInformation");
}
ViewBag.Created是取決於如果用戶數據已經被插入或者僞或真數據庫成功並且功能已經完成。
和_AddUserInformation.cshtml有其他信息正在嘗試註冊的用戶,如地址和國家...
希望這解釋更好的我的問題。
需要改進你的問題,讓其他誰已經看到你的應用程序可以理解一些基本知識......就像「從哪裏加載」?很難操作和編寫不可見的代碼html – charlietfl
如果您使用ajax,應該沒有問題。對我來說,儘管如此,您需要發佈代碼或至少一些示例代碼。 –
歡迎來到計算器!如果可能的話,最好爲您的問題提供示例代碼,以提高發布後的準確性並獲得更好的結果。有一個偉大的一天:) –