簡體   English   中英

數據未在 MVC 控制器中為 select2 列表框 Mvc 發布

[英]Data is not posting in MVC Controller for select2 List Box Mvc

我在視圖中使用多選文本框.. 下面是我的代碼

看法:

@using (Ajax.BeginForm("Multiple", "Home",  new AjaxOptions { HttpMethod = "POST" }))
{
<div class="col-md-2  col-xs-2">Associated Segment</div>
    <div class="col-md-4  col-xs-4">
        @Html.ListBoxFor(model => model.SegmentList, new MultiSelectList(ViewBag.List, "Value", "Text", Model.SegmentList.AsEnumerable()), new { @class = "form-control tokenizationSelect2", @multiple = "multiple" })
    </div>

    <div class="col-md-12  col-xs-12">
        <div class="pull-right" style="padding:1%;">
            <button class="btn btn-sm btn-primary" id="btnSaveProbDiagnosis" type="submit" name="">save</button>
        </div>
    </div>

}
<link href="~/scripts/select2.min.css" rel="stylesheet" />
<script src="~/scripts/jquery-1.10.2.js"></script>
<script src="~/scripts/select2.js"></script>
<script src="~/scripts/select2.full.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $(".tokenizationSelect2").select2({
            placeholder: "Your favourite car", //placeholder
            tags: true,
            tokenSeparators: ['/', ',', ';', " "]
        });
    })
</script>

控制器:

        [HttpPost]
        public ActionResult Multiple(ViewModal viewmoddal)
        {                
            return View();
        }

模態:

public class ViewModal
    {
       public int QuestionId { get; set; }
       public string question { get; set; }
       public string type { get; set; }
       public List<SegmentList> SegmentList { get; set; }
       public List<Answer> option { get; set; }

    }

它在 UI 中完美綁定數據。 但是當我將數據發布到控制器時,數據不會發送到控制器。

有人請幫助我...

您需要定義整數數組以綁定到多選,這些將被發布到控制器動作。 for.eg 在你的情況下像這樣定義你的模型。

public class ViewModal
{
  public int[] SelectedSegments { get; set; }
  public List<Segment> SegmentList { get; set; }
}

並且鑒於

@Html.ListBoxFor(model => model.SelectedSegments, new MultiSelectList(ViewBag.List, "Value", "Text", Model.SegmentList.AsEnumerable()), new { @class = "form-control tokenizationSelect2", @multiple = "multiple" })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM