Click here to Skip to main content
15,849,996 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello All,

I am performing CRUD operation in MVC.
I am stuck with checkbox.

I am simple using html checkbox controls.

For database connectivity i am using Entityframework technology.

<div class="col-sm-4">
<input type="checkbox" name="Hobbies" value="Reading" />Reading
<input type="checkbox" name="Hobbies" value="Travelling" />Travelling
<input type="checkbox" name="Hobbies" value="Sleeping" />Sleeping

Please help me.

What I have tried:

I know how to do in webforms and but not getting any idea about MVC.

Got some airticle on crud operation, but that doesnot contain checkbox control.
Updated 14-Jul-17 0:39am
F-ES Sitecore 14-Jul-17 4:35am    
MVC is a presentation framework, it doesn't have the capability of doing CRUD, for that you must be using a database-access technology but you haven't said what that technology is. We also don't know if your problem is reading the textboxes or updating the database. If you google for both I'm sure you'll find articles that cover how to do these things.
aditya2314 14-Jul-17 5:33am    
I am using Enity framework and i am able to insert data to database. I am finding only issue to update checkbox value.
aditya2314 14-Jul-17 5:35am    
THis is how i use to save multiple checkbox value to database in web forms.

string HOB = "";
for (int i = 0; i < Chklist.Items.Count; i++)
if (Chklist.Items[i].Selected == true)
HOB += Chklist.Items[i].Text + ",";
HOB = HOB.TrimEnd(',');

But not getting idea in mvc?
F-ES Sitecore 14-Jul-17 5:43am    
Have your action

public ActionResult MyAction(string[] hobbies)

Your "hobbies" array is now a list of the selected values
aditya2314 14-Jul-17 6:20am    
Dear sir,

Below is the model.
public partial class Student
public int Id { get; set; }
public string Name { get; set; }
public string MobileNo { get; set; }
public string Age { get; set; }
public string Qualification { get; set; }
public string Hobbies { get; set; }
public string Gender { get; set; }
public string FilesName { get; set; }
public Nullable<system.datetime> CreatedDate { get; set; }
public Nullable<system.datetime> UpdatedDate { get; set; }
public Nullable<bool> Status { get; set; }

Below is the controller.
public ActionResult Create(Student objStudent, string[] hob)
Student oStudent = new Student();
objStudent.CreatedDate = DateTime.Now;
objStudent.Status = true;
return RedirectToAction("/Index", "Student");
catch (Exception ex)
throw ex;

I am getting only one checkbox value in ObjStudent object.

Please help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900