[HttpPost] public ActionResult AddMachine(FormCollection fc, HttpPostedFileBase file) { admachinecat(); //admachinesubcat(); ad.machinetype = fc["Drop"]; ad.machinesubtype = fc["sDrop"]; ad.machinesub_subtype = fc["subDrop"]; ad.modelnum = fc["modelnum"]; ad.menufacture = fc["Manufacturer"]; ad.manufacturecat = fc["modelcat"]; ad.File = file; ad.productspec = fc["product_speci"]; ad.productdetail = fc["Editor1"]; if (ModelState.IsValid) { int result = dab.admachine(ad); ViewData["result"] = result; ModelState.Clear(); return View(); } else { ModelState.AddModelError("", "error in saving data"); return View(); } } public void admachinecat() { DataSet ds = dab.subcatdropdown(); ViewBag.menulist = ds.Tables[0]; List<SelectListItem> branchitems = new List<SelectListItem>(); branchitems.Add(new SelectListItem { Text = "---select---", Value = "0", }); foreach (DataRow dr in ViewBag.menulist.Rows) { branchitems.Add(new SelectListItem { Text = @dr["Category_Name"].ToString(), Value = @dr["Category_Id"].ToString() }); } ViewBag.Drop = branchitems; } IN DATABASE ACCESS LAYER: public DataSet subcatdropdown() { SqlCommand cmd = new SqlCommand("select Category_Id,Category_Name from Category", con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); return ds; } in HTML pAge: <div class="col-sm-6">@Html.DropDownList("Drop") What I have tried: i do all this. but it store in database dropdown selected value. but i want to store text. how can i do that?</div>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)