0
我想显示和编辑“许可证申请表”编辑模型。 如果它是一张纸的顶部将有个人信息填写。 底部将是,在每行的最后一个空白问题垂直列表写一个答案,每一个问题。MVC @Razor查看与收藏
所以我的模型是一个“请求者”对象(申请人),哪些是一个字符串“答案”产权问题“响应”对象的数组包含PermitApplication对象。
很多颠簸约我来的结论,也许什么,我想不MVC下工作后。即将这种模型赋予视图,编辑个人细节,填写问题的答案并将模型返回。 视图显示OK,但按下提交按钮时,传回控制器的PermitApplication对象只会填写人员详细信息。返回的响应对象为空。 我的MVC技巧和理解有限,所以我的问题是'解决这种情况的正确方法是什么?我查看(最新尝试)如下:
@model PermitApply.Models.LclPermitApplication
@using (Html.BeginForm())
{
<div class="form-group">
@Html.LabelFor(model => model.Requestor.FirstName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Requestor.FirstName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Requestor.FirstName, "", new { @class = "text-danger" })
</div>
</div>
<h2>Permit Questions</h2>
<table class="table">
<tr>
<th>
Question Id
</th>
<th>Question</th>
<th>QuestionTypeId</th>
</tr>
@foreach (var item in Model.Responses)
{
<tr>
<td>
@Html.DisplayFor(p => item.QuestionId)
</td>
<td>
@Html.DisplayFor(p => item.Question)
</td>
<td>
@Html.DisplayFor(p => item.QuestionTypeId)
</td>
<td>
<div class="col-md-10">
@Html.EditorFor(p => item.Answer, new { id = item.QuestionId })
@Html.ValidationMessageFor(p => item.Answer, "", new { @class = "text-danger" })
</div>
</td>
</tr>
}
</table>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
}
试过这个没有改变。按照顶部的“重复链接”中的方法,此工作。即对于(int i = 0; i p.Responses [i] .Answer工作,感谢您指向正确的方向。 –
@BobClegg好酷。 – User3250