TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rajesh Gami
81
24.4k
1.3m
Multiple selected dropdown value pass from viewTOcontroller
Jul 23 2018 2:14 AM
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"
});
}
}
View:
<div
class
=
"col-md-4 form-group"
>
<div
class
=
"entry-1"
>
@Html.LabelFor(model => model.EMPArea,
"Area"
, htmlAttributes:
new
{ @
class
=
""
})<span style=
"color:red;"
>*</span>
@Html.DropDownListFor(model => model.EMPArea,
new
SelectList(ViewBag.Area,
"ARMName"
,
"ARMName"
),
new
{ @
class
=
"form-control "
, @multiple =
"multiple"
, @id =
"multiArea"
})
</div>
</div>
<link href=
"~/Content/bootstrap.min.css"
rel=
"stylesheet"
/>
<script src=
"~/Scripts/jquery-1.10.2.min.js"
></script>
<script src=
"~/Scripts/bootstrap.min.js"
></script>
<script src=
"~/Content/js/bootstrap-multiselect.js"
></script>
<link href=
"~/Content/bootstrap-multiselect.css"
rel=
"stylesheet"
/>
<script type=
"text/javascript"
>
$(function () {
$(
'#multiArea'
).multiselect({
includeSelectAllOption:
true
});
$(
"#selected"
)
.click(function () {
var str =
""
;
$(
"#multiArea option:selected"
).each(function () {
str +=$(
this
).text() +
","
;
console.log(str);
});
})
.trigger(
"change"
);
});
</script>
i wll get my value in console.log(str) like Ahmedabad,Rajkot,Surat store only one in database. If any solution then qucikly reply me.
Thanks
Reply
Answers (
1
)
Barcode print in c# application
My C language Basic Coding Problem.