C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Multi-Select Dropdown With Checkbox To Insert Values Into Database In MVC 4
WhatsApp
Abhilash J A
8y
21.1
k
0
1
25
Blog
Hello everyone,
Here, I am trying to implement past checkbox's checked values to the controller and the database. With respect to this information, you can refer to
Multi-Select Dropdown With Checkbox In MVC 4
/*Inside js file*/
jQuery(document).on(
"change"
,
".chkclass"
,
function
() {
var
id =
""
;
$(
'input[class="chkclass"]'
).each(
function
(e) {
if
(
this
.checked) {
id = id + $(
this
).val()+
','
;
}
});
function
SaveSelecteItems(id) {
$.ajax({
type:
"POST"
,
url:
"/YourControllerName/YourAddMethodName/"
,
data: JSON.stringify({
id: id.toString();
}),
contentType:
"application/json; charset=utf-8"
,
dataType:
"json"
,
async:
false
,
success:
function
(result) {
alert(
'Successfully Saved!!!'
)
}
});
}
});
Then inside controller
public
ActionResult SmartSaveCheckedItems(
string
id)
{
var eachId = id.Split(
new
[] {
","
}, StringSplitOptions.RemoveEmptyEntries).Distinct();
foreach
(var item
in
eachId)
{
//Save or do your action
}
}
People also reading
Membership not found