При попытке отправить значения словаря в контроллер из представления, свойство словаря в модели говорит, что существует счетчик 0. Я надеялся получить коллекцию 'QuestionID' вместе с выбранным ответом для этоговопрос (AnswerID).Надеюсь, что кто-то может помочь, дайте мне знать, если нужны дополнительные детали!
***** Просмотр *****
@model HealthSafetyFramework.Models.mTourMain
@using (Html.BeginForm("SaveTour", "Tours", null, FormMethod.Post))
{
foreach (var y in Model.TourQuestions.Values.Select(y => y.QuestionGroupId).Distinct())
{
<b style="color:#0097b2; font-size:20px;">@HealthSafetyFramework.Factories.fTours.GetGroupTitle(y)</b>
foreach (var x in Model.TourQuestions.Where(x => x.Value.QuestionGroupId == y))
{
<div class="row">
<div class="col-md-6">
<h5>@x.Value.Seq - @x.Value.QuestionTitle</h5>
</div>
<div class="col-md-6">
@Html.HiddenFor(c => c.TourQuestions[x.Key].QuestionId)
<br />
@Html.DropDownListFor(c => c.TourQuestions[x.Key].AnswerID, new SelectList(Model.AnswerLu, "AnswerID", "Title"), new { @class = "form-control" })
</div>
</div>
}
}
<div class="row">
<div class="col-md-12">
<button type="submit" class="btn btn-sm btn-success form-control"><i class="fa fa-save"></i>Save</button>
</div>
</div>
}
***** Контроллер *****
public ActionResult SaveTour(HealthSafetyFramework.Models.mTourMain c)
{
throw new NotImplementedException();
}
****Модель ****
public class mTourMain
{
public int TourTypeId { get; set; }
public int SelectedScheduleId { get; set; }
public int CurrentScheduleId { get; set; }
public List<DataObjects.Tours.Schedule> Schedules { get; set; }
public List<DataObjects.Tours.Form> Forms { get; set; }
public Dictionary<int, DataObjects.Tours.Question> TourQuestions { get; set; }
public List<DataObjects.Tours.AnswerLU> AnswerLu { get; set; }
public bool isAdmin { get; set; }
public mTourMain(int TourTypeId)
{
this.TourTypeId = TourTypeId;
this.CurrentScheduleId = Factories.fTours.GetCurrentSchedule(TourTypeId);
this.Schedules = Factories.fTours.GetSchedulesByID(TourTypeId);
this.AnswerLu = Factories.fTours.GetAnswerLUs();
}
public mTourMain()
{
}
}