I want to INSERT employee attendance into database where i have a department dropdown and on selection of department, html table is filled with all emp code, emp name and a dropdown with attendance status(present/absent) related to selected department and on submit it is inserted in database with department name,emp code,emp name, status in mvc
this is TblEmpAttendance model
namespace SchoolManagementSystem.EFModel
{
using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;
public partial class TblEmpAttendance
{
public int Emp_Attendance_Id { get; set; }
public string Session { get; set; }
public int Emp_Type_Id { get; set; }
public string Emp_Type { get; set; }
public int Emp_Dept_Id { get; set; }
public string Emp_Deptartment { get; set; }
public System.DateTime Date { get; set; }
public int Emp_Official_Id { get; set; }
public string Emp_Code { get; set; }
public string Emp_Name { get; set; }
public int Status_Id { get; set; }
public string Status { get; set; }
[ScriptIgnore]
public TblDepartment TblDepartment { get; set; }
[ScriptIgnore]
public TblEmployeeOfficialDetail TblEmployeeOfficialDetail { get; set; }
[ScriptIgnore]
public TblEmployeeType TblEmployeeType { get; set; }
}
}
This is my EF model
@model SchoolManagementSystem.EFModel.TblEmpAttendance
@using (Html.BeginForm("InsertEmpAttendanceAction", "Employee", FormMethod.Post))
{
<div>
<div class="form-group" style="width :50%; float:left; padding-right:10px">
<label>SESSION</label> <br />
<input type="text" class="form-control font" id="ses" name="ses" value="2015-2016" readonly>
</div>
<div class="form-group" style="width: 50%; float: right; padding-right: 10px">
<label>DATE</label> <br />
<input type="text" class="form-control font" id="Date" name="Date" value="@Model.Date.ToShortDateString()">
</div>
</div>
<div>
<div class="form-group" style="width :50%; float:left">
<label>EMPLOYEE TYPE</label> <br />
@foreach (var type in ViewBag.Type_IdList)
{
<input type="radio" name="type" value="@type.Value" style="font:bold 16px verdana" /> <label>@type.Text</label> <br />
}
</div>
<div class="form-group" style="width :50%; float:right">
<label>EMPLOYEE DEPARTMENT</label> <br />
@Html.DropDownList("DDLDepartment", ViewBag.Department_IdList as SelectList,"--SELECT DEPARTMENT--", new { @class = "ddlfont" })
</div>
</div>
<div id="original" hidden>
@Html.DropDownList("DDLStatus", ViewBag.Status_IdList as SelectList, new {@class = "ddlfont" })
</div>
<div class="form-group font" id="attend">
<table>
<tr>
<th>EMPLOYEE CODE</th>
<th>EMPLOYEE NAME</th>
<th>ATTENDANCE</th>
</tr>
<tr>
</tr>
</table>
</div>
I am filling the table using jQuery and it is properly filled:
$(document).ready(function () {
$("#DDLDepartment").click(function () {
$("#Emp_Deptartment").val($("#DDLDepartment option:selected").text());
$("#Emp_Dept_Id").val($("#DDLDepartment option:selected").val());
$('#attend table tr:not(:first)').remove();
var deptid = parseInt($('#DDLDepartment').val());
console.log(deptid);
if ($('#DDLDepartment').val() != "--SELECT DEPARTMENT--") {
$.ajax({
url: "@Url.Action("GetEMPDetails", "Employee")",
type: "GET",
data: { DeptId: deptid },
dataType: "json",
contentType: "application/json",
processdata: true,
success: function (data) {
var dropdown = $('#DDLStatus').clone();
$.each(data, function (i, empdetail) {
console.log(empdetail);
$('#attend table').append("<tr><td>" + empdetail.Employee_Code + "</td><td>" + empdetail.Employee_Name + "</td><td>" + "<span class='abc'></span>" + "</td></tr>");
$('.abc').html(dropdown);
//$("#Emp_Official_Id").val(empdetail.Employee_Official_Id);
});
},
});
}
else {
alert(" PLEASE SELECT VALID DEPARTMENT ")
}
});
});
In My controller
public ActionResult InsertEmpAttendanceAction(TblEmpAttendance empattendanceobj, **ICollection<TblEmpAttendance> attendance**)// here i was stuck as it returns null
{
}