locked
dropdownlist RRS feed

  • Question

  • User-1686372396 posted

    I'm looking for a sample of how to generate a dropdownlist from a model in vb.net mvc 3.

    It seems almost everything is written in C# but I have to do it in vb.NET

    I was trying this:

    Private _Q1 As IEnumerable(Of SelectListItem)
    Public Property Question1() As IEnumerable(Of SelectListItem)
    Get
    Return _Q1
    End Get
    Set(ByVal value As IEnumerable(Of SelectListItem))
    _Q1 = value
    End Set
    End Property

    but it is ignored.

    Tuesday, June 19, 2012 2:38 PM

Answers

All replies

  • User-821857111 posted

    Use a code converter: http://www.codechanger.com

    Tuesday, June 19, 2012 2:55 PM
  • User1653304669 posted

    I'm have a sample code in C#:

    In Controller:

    List<SelectListItem> list = new List<SelectListItem>();
                list.Add(new SelectListItem { Text = "-Lựa chọn-", Value = "Selects items" });
                var cat = (from c in _database.SubCategories where c.Categories.CategoryId==1 select c).ToArray();
                for (int i = 0; i < cat.Length; i++)
                {
                    list.Add(new SelectListItem { Text = cat[i].SubCategoryName, Value = cat[i].SubCategoryId.ToString(), Selected = (cat[i].SubCategoryId == article.SubCategoryId) });
                }
                ViewData["danhsach"] = list;

    In View:

    <td>@Html.DropDownList("SubCategoryId", (IEnumerable<SelectListItem>)ViewData["danhsach"],
    new { id = "SubCategoryId" })</td>

    You can reference and apply to your vb code Thanks for reading my post

    Cool

    Tuesday, June 19, 2012 10:25 PM
  • User-1686372396 posted

    Should this code not be in your model?

    I'm trying to get this to work from the model without the database.

    Wednesday, June 20, 2012 7:55 AM
  • User-1686372396 posted

    Well thanks for that:

    The code it produced was:

    Public Property Products() As IEnumerable(Of SelectListItem)
    Get
    End Get
    Set(value As IEnumerable(Of SelectListItem))
    End Set
    End Property

    But it does not work...

    Wednesday, June 20, 2012 7:59 AM
  • User1954304945 posted

    Hi, please refer to the replies on the following link:

    http://forums.asp.net/t/1741846.aspx/1

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 21, 2012 3:18 AM