Hi,
I am using Html.DropDownListFor as in view page:
<td>
<%:Html.DropDownListFor(m => m.ddlCategory_NewQuestion, Model.Category)%>
</td>
In Controller:
Model.Category.Add(new SelectListItem { Text = "--Select--", Value = "", Selected = false });
var CategoryList = from c in db.tbl_Categories orderby c.Priority select c;
foreach (var item in CategoryList)
{
if (item.CategoryShortName == "")
{
SelectListItem =new SelectListItem();
SelectListItem.Selected =true;
SelectListItem.Text = item.Category;
SelectListItem.Value = item.CategoryShortName;
Model.Category.Add(SelectListItem);
}
else
{
Model.Category.Add(new SelectListItem() { Selected = false, Text = item.Category, Value = item.CategoryShortName });
}
}
In Model:
public class QuestionModel
{
public QuestionModel() {
Category =new List<SelectListItem>();
}
[DisplayName("Category")]
public int ddlCategory_NewQuestion { get; set; }
public List<SelectListItem> Category { get; set; }
}
Views:
9418
Total Answered:
1
Total Marked As Answer:
0
Posted On:
09-Jun-2015 02:14