How To Declare ListBox Using ViewData In MVC

In this article i explain you how to declare ListBox Using ViewData in mvc.
    @using(Html.BeginForm())
    {
        List<SelectListItem> objSelectItem = new List<SelectListItem>()
        {
            new SelectListItem{Text="Option1",Value="1"},
            new SelectListItem{Text="Option2",Value="2"},
            new SelectListItem{Text="Option3",Value="3"},
            new SelectListItem{Text="Option4",Value="4"}
        };
        ViewData["ListBox1"] = objSelectItem;
        @Html.ListBox("ListBox1")    
    }

No comments:

Post a Comment