【发布时间】:2015-07-29 05:18:48
【问题描述】:
我想将员工出勤插入到我有部门下拉列表的数据库中,在选择部门时,html 表中填充了所有 emp 代码、emp 名称和一个下拉列表,其中包含与所选部门相关的出勤状态(存在/缺席)和在提交时将其插入到数据库中,其中包含部门名称、员工代码、员工名称、mvc 中的状态
这是 TblEmpAttendance 模型
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; }
}
}
这是我的 EF 模型
@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>
我正在使用 jQuery 填充表格,并且已正确填充:
$(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 ")
}
});
});
在我的控制器中
public ActionResult InsertEmpAttendanceAction(TblEmpAttendance empattendanceobj, **ICollection<TblEmpAttendance> attendance**)// here i was stuck as it returns null
{
}
【问题讨论】:
-
欢迎来到stackoverflow。请阅读How to Ask。
-
你的代码在哪里,你卡在哪里了?
-
现在帮我解决这个问题...
-
您的生成表单控件具有
name属性,这些属性与您的模型完全没有关系,因此在您回发时不会绑定。至少您需要向您展示TblEmpAttendance的模型以帮助您解决此问题(提示:您必须使用for循环或自定义EditorTemplate,而不是foreach循环并使用强烈生成您的html types html helpers)既然你声称你的脚本正在工作,你为什么要包含它(它与问题有什么关系)? -
好的,我删除了 foreach 循环并添加了 TblEmpAttendance
标签: jquery sql-server asp.net-mvc