language use: asp.net MVC.
How to pass multiple selected value from view to controller and store into database with same ID.
E.x :
i selected cities in dropdown : Ahmedabad, Baroda, Rajkot then store database in like
| ID | Name | City | Status |
| 1 | RG | Ahmedabad, Baroda, Rajkot | True |
how it possible.
here is my original code
Controller:
- public ActionResult Create()
- {
- if (Session["AdminId"] != null)
- {
- ViewBag.Area = _areaContext.AreaMaster.ToList();
- ViewBag.Network = _networkContext.NetworkMaster.ToList();
- return View();
- }
- else
- {
- return RedirectToAction("Login", "Admin", new { area = "Admin" });
- }
- }
- [HttpPost]
- public ActionResult Create(EmployeeMaster packageMaster)
- {
- if (Session["AdminId"] != null)
- {
- if (ModelState.IsValid)
- {
- _employeeContext.EmployeeMaster.Add(packageMaster);
- _employeeContext.SaveChanges();
- packageMaster.EMPEnc = enc.Encrypt(packageMaster.EMPId);
- _employeeContext.SaveChanges();
- return RedirectToAction("Index");
- }
- else
- {
- ViewBag.Area = _areaContext.AreaMaster.ToList();
- ViewBag.Network = _networkContext.NetworkMaster.ToList();
- return View();
- }
- }
- else
- {
- return RedirectToAction("Login", "Admin", new { area = "Admin" });
- }
- }
- class="col-md-4 form-group">class="entry-1">
- @Html.LabelFor(model => model.EMPArea, "Area", htmlAttributes: new { @class = "" })"color:red;">*
- @Html.DropDownListFor(model => model.EMPArea, new SelectList(ViewBag.Area, "ARMName", "ARMName"), new { @class = "form-control ", @multiple = "multiple", @id = "multiArea" })
- "~/Content/bootstrap.min.css" rel="stylesheet" />
- "~/Content/bootstrap-multiselect.css" rel="stylesheet" />
-
Thanks

Rajesh GamiPosted Jul 23, 2018, 5:30 AM