I'm working in a HR project in ASP.NET MVC using Entity Framework with a database-first approach.
My view markup is:
<div class="form-group">
@Html.LabelFor(model => model.emp_Disease, htmlAttributes: new { @class = "control-label col-md-2 " })
<div class="col-md-10" style="padding-top:6px;margin:0px;">
@Html.CheckBoxListFor(m => m.emp_Disease,m=> m.Disease,s => s.Name, s => s.Name,s => s.emp_Disease,MvcCheckBoxList.Model.Position.Horizontal)
</div>
</div>
Controller action is:
[HttpPost]
public ActionResult Home(tbl_employee emp)
{
using (hrm_DB db = new hrm_DB())
{
if (emp.emp_Id == 0)
{
db.tbl_employee.Add(emp);
db.SaveChanges();
TempData["SaveMessage"] = "Save Record Succesfully! ";
}
else
{
db.Entry(emp).State = EntityState.Modified;
db.SaveChanges();
TempData["EditMessage"] = "Change Succesfully! ";
}
}
return RedirectToAction("ViewAll");
}
My model classes are:
public partial class tbl_employee
{
[DisplayName("AnyDisease")]
public string[] emp_Disease { get; set; }
public List<Checkdisease> Disease { get; set; }
}
public class Checkdisease
{
public int id { get; set; }
public string Name { get; set; }
public bool emp_Disease { get; set; }
}
Only store the one value. My problem is not submit the array store in database. How to store the string[] in database model ?