我有一个呈现局部视图的视图,在此视图中有一个对话框,其中包含一个复选框列表。此视图称为Create。
此页面的处理流程为:
1)用户首次打开此页面时,会通过选择文件并点击上传按钮来上传文件。 action方法解析文件并返回模型,并以复选框列表的形式在对话框中显示一组日期。
2)在此对话框中,他们选择/检查日期并使用对话框中的选择按钮,对控制器操作发出请求,基于所选的checbox计算一些表单字段并返回部分视图。
3)一旦用户可以使用预先填充的字段返回,他们点击保存并保存记录。
“创建”页面上的一切正常。在编辑页面中,它似乎是一个不同的故事。第一次加载页面时,对话框中会出现在创建时保存的列表。但是,当他们在对话框中点击“选择”时,操作方法的帖子会将此列表视为空。我不确定为什么它是null。不确定我到底做错了什么,但编辑的代码如下。
谢谢!
THE JS FILE:
var RunDialog;
$(document).ready(function () {
$(document).ajaxStart($.blockUI).ajaxStop($.unblockUI);
RunDialog = $("#runDatestreeview").dialog({ closeOnEscape: true, stack: false, autoOpen: false,
modal: false, resizable: true, draggable: true, title: 'Select Run Dates to Auto-Populate Form Fields:',
width: 600, height: 500, position: 'center',
buttons: { Select: function () {
$.post("/RunLogEntry/LogFileConfirmation",
$("#form").serialize(),
function (data) {
$("#runDatestreeview").remove();
$("#testExceptiontreeview").remove();
$("#main").html(data);
$(RunDialog).dialog("close");
}, "html");
},
Cancel: function () {
$(this).dialog("close");
}
}
});
RunDialog.closest("div.ui-dialog").appendTo("#form");
$('#RunDatesChildDialogLink').click(function () {
$(RunDialog).dialog("open");
});
//Region Auto-Open Modal Box
var modalOpen = $("#LogModals").val();
if (modalOpen == "0") {
$("#runDatestreeview").dialog({ autoOpen: true });
}
//End Auto Open Modab Box Regiom
});
编辑视图
@model RunLog.Domain.Entities.RunLogEntry
@{
ViewBag.Title = "Update";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/runLogEntry.js")" type="text/javascript"></script>
<script type="text/javascript">
var runlogListErrorsUrl = '@Url.Action("ListErrorCodes", "RunLogEntry")';
</script>
@using (Html.BeginForm("Edit", "RunLogEntry", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div id="main">
@Html.Partial("_RunLogEntryPartialViewEdit", Model)
</div>
}
<script src="@Url.Content("~/Scripts/exitCode.js")" type="text/javascript"></script>
编辑的部分视图为了便于阅读,我没有发布整个模型。 Dialog div称为runDAtestreeview
。
@model RunLog.Domain.Entities.RunLogEntry
<script src="@Url.Content("~/Scripts/runDates.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/testexception.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.blockUI.js")" type="text/javascript"></script>
@Html.ValidationSummary(true)
<div class="bodyContent">
@if (Model.RunDatesDisplay != null && Model.RunDatesDisplay.Count() > 0)
{
<span class="leftContent">
@Html.Label("Run Dates")
</span><span class="rightContent"><span id="RunDatesChildDialogLink" class="treeViewLink">
Click here to Select/View Run Dates</span>
<br />
<span id="RunDatesDisplayy" style="cursor: pointer; text-decoration: underline;">
</span></span>
}
</div>
<div id="runDatestreeview" title="Dialog Title" style="font-size: 10px; font-weight: normal;
overflow: scroll; width: 400px; height: 450px; display: none;">
<table class="grid" style="width: 600px; margin: 3px 3px 3px 3px;">
<thead>
<tr>
<th>
Run Dates:
</th>
<th>
Minimum Replicate:
</th>
</tr>
</thead>
<tbody>
@Html.EditorFor(x => x.RunDatesDisplay)
</tbody>
</table>
</div>
答案 0 :(得分:0)
好的,这似乎微不足道,但通过包含“id = form”将表单更改为以下内容使其工作。当我点击选择按钮时看起来像早些时候,表格是空的。
@using (Html.BeginForm("Create", "RunLogEntry", FormMethod.Post, new { id = "form", enctype = "multipart/form-data" }))
{