-1

View

 @for (int i = 1; i < Convert.ToInt32(Model.qc_choice) + 1; i++)
        {
            <span>Question @i</span>
            @Html.TextAreaFor(m => m.MTfull[i].qc_selectedchoice)

            <span>Answer @i</span>
            @Html.TextBoxFor(m => m.MTfull[i].qc_answer)
            <br />
        }
        <p>
            <input type="submit" value="Create" name="submitBtn" />
        </p>

Controller

    [HttpGet]
    public ActionResult checkMT(string quiz_id)
    {
        List<Models.QuizMaker> qm = new List<Models.QuizMaker>();
        var model = new Models.QuizMaker
        {
            act_id = quiz_id,
        };
        return View(model);
    }

    [HttpPost]
    public ActionResult checkMT(QuizMaker qm)
    {
        return RedirectToAction("createMatchingType", "QuizMaker", new { quiz_id = qm.act_id, choice = qm.qc_choice });
    }

    [HttpGet]
    public ActionResult createMatchingType(string quiz_id, string choice)
    {
        List<Models.QuizMaker> qm = new List<Models.QuizMaker>();
        var model = new Models.QuizMaker
        {
            act_id = quiz_id,
            qc_choice = choice,
        };
        return View(model);
    }

This is how the qc_choice is populated it is coming from the user

then it will loop the controls on how many the user inputed.

But whatever I do The value of the List MTfull model is always null in my controller help is much appreciated.

Renz Zz
  • 1
  • 1
  • How is the model populated? Can you paste your Controller/ViewModel code? – Darren Feb 06 '16 at 13:37
  • Didn't you already asked this question here: http://stackoverflow.com/questions/35066534/how-can-i-retrieve-radiobuttonin-nested-loop-values-to-my-controller and ALSO as another user here: http://stackoverflow.com/questions/35037333/how-to-get-value-of-a-radiobuttonforcreated-using-loop/35037899#35037899 ? Why don't you follow the answers + generating more duplicate users ? – Orel Eraki Feb 06 '16 at 13:56
  • 1
    @OrelEraki can't you just answer my question rather than pointing me to another threads? – Renz Zz Feb 06 '16 at 14:10
  • Why your MTfull should be null if you never fill it in controller (as I understand, method createMatchingType fills model for this view)? – Oleg Sh Feb 06 '16 at 15:05
  • @OlegSh i just didn't show my post method but i filled it. anyway i just solved my own problem. thanks for the response ;) – Renz Zz Feb 06 '16 at 16:25

1 Answers1

0

The Problem is in the for loop statement.

@Html.TextAreaFor(m => m.MTfull[i].qc_selectedchoice)

meaning it is expecting index of [i] and i = 1,

it doesn't accept index if 1 instead changed it to 0.

list is accepting index of 0 not index of 1

Renz Zz
  • 1
  • 1