텍스트 파일이 있고 사용자가 파일을 업로드하면 컨트롤러 작업 메서드는 상태 시스템을 사용하여 해당 파일을 구문 분석하고 일반 목록을 사용하여 일부 값을 저장합니다 . 이 뷰를 IEnumerable 형태로 다시 전달합니다. 내 기본보기 내에서이 ienumerable 목록을 기반으로 항목을 반복하고 레이블과 텍스트 영역을 표시하기위한 partail보기를 렌더링합니다. 사용자는 텍스트 영역에 입력 내용을 추가 할 수 있습니다. 사용자가 저장 단추를 누르면 렌더링 된 부분 뷰에서이 iumumrable 목록이 null입니다. 그래서 어떤 해결책을 조언하십시오. 다음과 같이 여기 보기 모델 렌더링 된 모델 내에서 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>
@[email protected]
</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)
{
}
문제는 사기꾼 테스트 예외입니다 예외 문자열을 무시하고 주석이 null로 되돌아갑니다.
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>
}
; 세트; } – user1475788
그러면이 @model RunLog.Domain.Entities.RunLogEntryTestExceptionDisplay에는 두 가지 속성, 즉 테스트 예외 문자열과 주석 문자열 – user1475788
이 주보기에 있습니다. im은 테스트 예외 표시를 루프 내에서 부분적으로 렌더링하므로 잘 렌더링됩니다. 게시물을 볼 수 없습니다. – user1475788