i used value the model for drop down list,
> public class Items
> {
> public int itemcategoryid { get; set; }
> public string itemcategory { get; set; }
> public int Itemsubcategoryid { get; set; }
> public string Itemsubcategoryname { get; set; }
> }
and below the code for controller
> ItemViewModel catVM = new ItemViewModel();
> List<Items> catlist = catVM.GetCategoryInfo();
> ViewBag.categorylist = catlist;
After binding drop down list using below the HTML code, the drop down list has populated and select default name as itemcategory but did not pass id of itemcategory pass only itemcategory name for POST.
@Html.DropDownListFor(model => model.itemcategory, new SelectList(ViewBag.categorylist, "itemcategory", "itemcategory", Model.itemcategory))
if i using below the HTML Code their pass value but did not select default name
@Html.DropDownListFor(model => model.itemcategory, new SelectList(ViewBag.categorylist, "itemcategoryid", "itemcategory", Model.itemcategory))
using below the code for retrieve data
using (OracleCommand cmd = new OracleCommand("PS_Category", conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; conn.Open(); OracleDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Items listitems = new Items(); ; listitems.itemcategoryid = Convert.ToInt32(reader["CATID"]); listitems.itemcategory = reader["CATNAME"].ToString(); items.Add(listitems); } }
Actually i want to to select default name and pass their id how can possible it??