0

When trying to post the dictionary values to the controller from the view, the dictionary property in the model is saying there is a count of 0. I was hoping to have a collection of the 'QuestionID' alongside the selected answer for that question (AnswerID). Hope someone can help, let me know if additional details are needed!

*****View*****

@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>
}

*****Controller*****

 public ActionResult SaveTour(HealthSafetyFramework.Models.mTourMain c)
    {
        throw new NotImplementedException();
    }

****Model****

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()
    {

    }

}
Arcturus
  • 26,677
  • 10
  • 92
  • 107
Kyle Eales
  • 41
  • 1
  • 6

0 Answers0