PDA

View Full Version : سوال: چگونه میشود تعداد زیادی DropDown را در یک صفحه قرار داد؟



sarah2
سه شنبه 18 اردیبهشت 1397, 08:02 صبح
قصد دارم حدودا 20 تا Dropdown را در یک صفحه قرار بدهم, آیا به غیر از Viewbag راهی هست؟

RIG000
سه شنبه 18 اردیبهشت 1397, 10:26 صبح
مستقیم با مدل هم میتونی

public class Data
{
public List<tbl_Dept> lstDepatrment;
public List<tbl_employees> lstEmployee;
//other



@model MVCApp.Models.Data
@{
var categoryList = Model.lstDepatrment.Select(cl => new SelectListItem
{
Value = cl.Dept_ID.ToString(),
Text = cl.Dept_Description == null ? String.Empty : cl.Dept_Description
});

}

و در ویو


@(Html.DropDownList("sampleDropdown", categoryList, "-----Select-----"))