0

I'm having problems creating a DropDownList in my Webgrid using ViewBag data. I'm passing the following data via my ViewBag:

enter image description here

I'm passing 3 objects of type JsonModel with 2 properties KeyA and KeyOther. The data I want to display into my DropDownList are the KeyOther values of my 3 objects.

What I've got now:

@{
                if (Model != null && Model.Count() > 0)
                {
                    var grid = new WebGrid(canPage: true, rowsPerPage: 10);
                    grid.Bind(source: Model, rowCount: 0, autoSortAndPage: false);

                    <div class="row" id="content2">
                        <div class="col-lg-12 d-flex align-items-stretch">

                            @grid.Table(tableStyle: "table table-responsive table-striped table-bordered",
                                columns: grid.Columns(
                                grid.Column(columnName: "KeyA", header: "KeysA", format:@<text><div class="" data-id="@item.KeyA" data-propertyname="KeyA">@item.KeyA</div></text>),
                                    grid.Column("Priority", format: @<text>@Html.DropDownListFor(x => x.First().KeyOther, new SelectList(ViewBag.OtherKeysList))</text>)
                                    ))
                        </div>
                        <!--Pagerlist for webgrid-->
                        <div class="col-lg-12 d-flex align-items-stretch">
                            @grid.PagerList(mode: WebGridPagerModes.All, paginationStyle: "pagination pagination-small pagination-right")
                        </div>

                        @Html.Hidden("dir", grid.SortDirection)
                        @Html.Hidden("col", grid.SortColumn)
                    </div>
                }
            }

Resulting in the follownig:

enter image description here

Hope someone can help!

Thanks in advance!

NielsStenden
  • 357
  • 1
  • 6
  • 25
  • duplicate: https://stackoverflow.com/questions/16594958/how-to-use-a-viewbag-to-create-a-dropdownlist – jazb May 16 '19 at 07:58
  • Possible duplicate of [How to use a ViewBag to create a dropdownlist?](https://stackoverflow.com/questions/16594958/how-to-use-a-viewbag-to-create-a-dropdownlist) – jazb May 16 '19 at 07:59

0 Answers0