Anisha Kumaradas

Anisha Kumaradas

  • 2.1k
  • 46
  • 9.2k

Saving Selected Checkbox in database using MVC

Feb 9 2018 5:26 AM
Requirement:To save selected checkbox  values in a table in database.
Model: 
public class Profiletemplate
{
public int RoleID { get; set; }
public string FieldName { get; set; }
public string BlockName { get; set; }
public int FieldID { get; set; }
}
 
Controller:
 if (ModelState.IsValid)
{
objent.sp_addProfileTemplate(pro.RoleID, pro.BlockName, pro.DisplayOrderBlock, pro.DisplayOrderField, pro.FieldID, pro.ValueType, pro.Maxlength, pro.IsRequired, pro.FieldColumnNumber, Convert.ToInt32(Session["ID"].ToString()));
return RedirectToAction("ProfileTemplate", "Admin");
}
 
View:
@foreach (var cat in Model.lstfields)
{
<label class="container">
@cat.FieldName
<input type="checkbox" id="@cat.FieldID" value="@cat.FieldName" class="chkclass" />
<span class="checkmark"></span>
</label>
}
I couldnot pass FieldID to my controller to save it in my database. 
Please help me to resolve this issue 
 Thanks in Advance.
 
Regards,
Anisha. 

Answers (1)