title: asp.NET mvc, get model list values from view
body: <p>I am new to mvc and am trying to do something like in the below image (im not using partial views).
  I have an IEnumerable property on Model
  <a href="https://i.stack.imgur.com/YlFsH.png" rel="nofollow noreferrer">Like in this image, (i have not enough reputation to show image directly)</a></p>
  
  <p>but on controller if i put FormCollection as parameter to accepting post method when i process same name fields i get an extra character ',', which might be also used by user...</p>
  
  <p>Any idea....</p>
  
  <p>[<em>EDIT</em>]
  My view</p>
  
  <pre><code>@model Models.Question
  @{
      ViewBag.Title = "Add";
  }
  
  &lt;h2&gt;Add&lt;/h2&gt;
  
  
  @using (Html.BeginForm())
  {
  @Html.AntiForgeryToken()
  
  &lt;div class="form-horizontal"&gt;
      &lt;h4&gt;Question&lt;/h4&gt;
      &lt;hr /&gt;
      @Html.ValidationSummary(true, "", new { @class = "text-danger" })
      @Html.HiddenFor(model =&gt; model.SurveyId)
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Name, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.Name, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.QuestionTypeId, "Question type", htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownListFor(model =&gt; model.QuestionTypeId, new SelectList(ViewBag.QuestionTypes, "QuestionTypeId", "Name"), new { @class = "form-control col-md-10" })
              &lt;button type="button" class="btn btn-default addAnswer hide"&gt;&lt;span class="glyphicon glyphicon-plus" aria-hidden="true"&gt;&lt;/span&gt;&lt;/button&gt;
              @Html.ValidationMessageFor(model =&gt; model.QuestionTypeId, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group hide"&gt;
          @Html.LabelFor(model =&gt; model.Answers, "Options", htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10" id="allAnswers"&gt;
              @Html.ValidationMessageFor(model =&gt; model.Answers, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Sort, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Sort, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.Sort, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Mandatory, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              &lt;div class="checkbox"&gt;
                  @Html.EditorFor(model =&gt; model.Mandatory)
                  @Html.ValidationMessageFor(model =&gt; model.Mandatory, "", new { @class = "text-danger" })
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-offset-2 col-md-10"&gt;
              &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  }
  
  &lt;div&gt;
  @Html.ActionLink("Back to List", "Question", "Survey", new { id = Model.SurveyId }, null)
  &lt;/div&gt;
  
  @section Scripts {
  @Scripts.Render("~/bundles/jqueryval", "~/Scripts/QuestionAdd.js")
  }
  </code></pre>
  
  <p><em>Controller</em></p>
  
  <pre><code>[HttpGet]
      public ActionResult Add(long id)
      {
          var question = new Models.Question();
          question.SurveyId = id;
          ViewBag.QuestionTypes = BLL.Questions.GetQuestionTypes();
          return View(question);
      }
      [HttpPost]
      public ActionResult Add(FormCollection coll)
      {
          if (ModelState.IsValid)
          {
              var question = new Models.Question();
              question.Name = coll["Name"];
              byte qid = 0, sort = 0;
              bool mandatory = false;
              byte.TryParse(coll["QuestionTypeId"], out qid);
              byte.TryParse(coll["Sort"], out sort);
              bool.TryParse(coll["Mandatory"], out mandatory);
              question.QuestionTypeId = qid;
              question.Sort = sort;
              question.Mandatory = mandatory;
              foreach (var answer in coll["Answers"])
                  question.Answers.Add(new Models.Answer() { Value = answer + "" });
              if (question != null)
              {
                  if (BLL.Questions.Insert(question) != null)
                      ViewBag.Message = "Successfully inserted";
                  else
                      ViewBag.Message = "Insert could not be done";
                  return RedirectToAction("Index", "Question", new { questionId = question.QuestionId });
              }
          }
          return View();
      }
  </code></pre>
  
  <p>When (+) clicked</p>
  
  <pre><code>$('#allAnswers').append(
      '&lt;div class="input-group col-lg-4"&gt;' +
      '&lt;input class="form-control" name="Answers"&gt; ' +
      '&lt;div class="input-group-btn"&gt;' +
      ' &lt;button type="button" class="btn btn-default removeAnswer"&gt;&lt;span class="glyphicon glyphicon glyphicon-trash" aria-hidden="true"&gt;&lt;/span&gt;&lt;/button&gt;' +
      '&lt;/div&gt; &lt;/div&gt;');
  </code></pre>