我有一个文本文件,当用户上传文件时,控制器操作方法使用状态机解析该文件并使用通用列表来存储一些值。我以 IEnumerable 的形式将其传递回视图。在我的主视图中,基于这个可枚举的列表,我渲染了一个部分视图来迭代项目并显示标签和文本区域。用户可以在文本区域中添加他们的输入。当用户点击保存按钮时,渲染的局部视图中的这个可枚举列表为空。所以请建议任何解决方案。
这是我的主要观点
@model RunLog.Domain.Entities.RunLogEntry
@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm("Create", "RunLogEntry", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div id="inputTestExceptions" style="display: none;">
<table class="grid" style="width: 450px; margin: 3px 3px 3px 3px;">
<thead>
<tr>
<th>
Exception String
</th>
<th>
Comment
</th>
</tr> </thead>
<tbody>
@if (Model.TestExceptions != null)
{
foreach (var p in Model.TestExceptions)
{
Html.RenderPartial("RunLogTestExceptionSummary", p);
}
}
</tbody>
</table>
</div>
}
部分观点如下:
@model RunLog.Domain.Entities.RunLogEntryTestExceptionDisplay
<tr>
<td>
@Model.TestException@
</td>
<td>@Html.TextAreaFor(Model.Comment, new { style = "width: 200px; height: 80px;" })
</td>
</tr>
控制器动作
[HttpPost]
public ActionResult Create(RunLogEntry runLogEntry, String ServiceRequest, string Hour, string Minute, string AMPM,
string submit, IEnumerable<HttpPostedFileBase> file, String AssayPerformanceIssues1, IEnumerable<RunLogEntryTestExceptionDisplay> models)
{
}
问题是包含异常字符串的测试异常,并且注释返回为空。
更新
public class RunLogEntry
{
SOME OTHER FIELDS
[NotMapped]
public IEnumerable<RunLogEntryTestExceptionDisplay> TestExceptions { get; set; }
}
public class RunLogEntryTestExceptionDisplay
{
public string TestException { get; set; }
public string Comment { get; set; }
}
@using (Html.BeginForm("Create", "RunLogEntry", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
if (Model.TestExceptions != null)
{
if (Model.TestExceptions.Count() > 0)
{
<div class="bodyContent">
<span class="leftContent">
@Html.Label("Test Exceptions")
</span><span class="rightContent"><span id="TestExceptionChildDialogLink" class="treeViewLink">
Click here to View Test Exceptions</span>
<br />
<span id="TestExceptionDisplay"></span>
@Html.HiddenFor(model => model.TestExceptions)
@*<input id="ExceptionString" type="hidden" value="@Model.ExceptionString" />*@
</span>
</div>
}
}
<div id="inputTestExceptions" style="display: none;">
<table class="grid" style="width: 450px; margin: 3px 3px 3px 3px;">
<thead>
<tr>
<th>
Exception String
</th>
<th>
Comment
</th>
</tr>
</thead>
@if (Model.TestExceptions != null)
{
var index = 0;
foreach (var p in Model.TestExceptions)
{
<tr>
<td>@p.TestException
<input type="hidden" name="RunLogEntry.TestExceptions[@index].ExceptionString" value="@p.TestException" />
</td>
<td>
<textarea name="RunLogEntry.TestExceptions[@index].Comment" style ="width: 200px; height: 80px;">@p.Comment</textarea>
<input type="hidden" name="RunLogEntry.TestExceptions[@index].Comment" value="@p.Comment" />
</td>
@* Html.RenderPartial("RunLogTestExceptionSummary", p);*@
</tr>
index++;
}
}
</table>
</div>
}