我正在做一个调查申请。调查有问题,问题有 QuestionOption。这里有一个例子。 我正在尝试以带有列表(列表)的大型形式使用此技术,但是当我回发时,应该包含项目和活动列表的 Viewmodel.Order 返回列表为空。
我的 QuestionModel.cs 就是这样。
public int Id { get; set; }
public string QuestionText { get; set; }
public System.Nullable<bool> OptionType1 { get; set; }
public System.Nullable<bool> OptionType2 { get; set; }
public List<QuestionOptionModel> OptionList = new List<QuestionOptionModel>();
当我发回“IEnumerable questions”时,List OptionList 为空。我怎样才能做到这一点?
public ActionResult CallSurvey()
{
IEnumerable<QuestionModel> questionModelList = (IEnumerable<QuestionModel>)SessionHelper.GetSessionObject(SessionKeys.SurveyKey);
questionModelList = questionSrv.GetQuestionModel();
return View(questionModelList);
}
questionModelList 包括我所有的调查问题和问题选项。当我发布它时,回发只带有空选项列表。
[HttpPost]
public ActionResult CallSurvey(IEnumerable<QuestionModel> questions)
{ ..... }
CallSurvey.cshtml
<body>
@using ((Html.BeginForm()))
{
@ViewBag.Test
<section class="slides layout-regular template-kendo">
@foreach (var item in Model)
{<article>
@Html.Partial("QuestionEditor", item)
</article>
}
<div class="slide-area" id="prev-slide-area"></div>
<div class="slide-area" id="next-slide-area"></div>
</section>
}
</body>
QuestionEditor.cshtml
@model LSMM.Business.Model.Survey.QuestionModel
@using LSMM.Web.Helpers
<div>
@using (Html.BeginCollectionItem("Questions"))
{
<table id="table1">
<tr>
<td>
<div id="@Model.Id" class="hint">
@Html.HiddenFor(m => m.Id)
@Html.HiddenFor(m => m.QuestionText)
@Html.HiddenFor(m => m.OptionType1)
@Html.HiddenFor(m => m.OptionType2)
@for (int i = 0; i < Model.OptionList.Count; ++i)
{
@Html.LabelFor(m => m.OptionList[i].Id)
@Html.LabelFor(m => m.OptionList[i].QuestionId)
@Html.LabelFor(m => m.OptionList[i].Checked)
@Html.LabelFor(m => m.OptionList[i].Description)
@Html.LabelFor(m => m.OptionList[i])
}
<span id="sorular">@Model.Id. @Model.QuestionText</span>
<br />
<br />
</div>
</td>
</tr>
<tr>
<td>
<div class="hint2">
@Html.Partial("QuestionOptionEditor", Model)
</div>
</td>
<td>
<div id="@Model.Id-Img">
<h2 style="top: 200px; right: 0;">
<img src="../../Content/css/img/@Model.Id-Img.png"></h2>
</div>
</td>
</tr>
</table>
和 QuestionOptionEditor.cshtml
@model LSMM.Business.Model.Survey.QuestionModel
@using LSMM.Web.Helpers
@foreach (var option in @Model.OptionList)
{
<p>
@if (@Model.OptionType1 == false)
{
@Html.Partial("QuestionOptionModel", option)
}
else
{
@Html.Partial("../Shared/DisplayTemplates/QuestionOptionModel", option)
}
</p>
}
这里的 QuestionOptionModel 视图是这样的;
@model LSMM.Business.Model.Survey.QuestionOptionModel
@(Html.RadioButtonFor(m => m.Id, true, new { Id = @Model.Id, Name = @Model.QuestionId })) @Html.Label("Evet")
<br />
<br />
@(Html.RadioButtonFor(m => m.Id, false ,new { Id=@Model.Id, Name = @Model.QuestionId})) @Html.Label("Hayır")