Watch Pre-recorded Live Shows Here
Why Join
Become a member
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
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
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.
Reply
Answers (
1
)
Message Preview with Number
return value in post method using async Task(C# And Mongodb)