Enrollnumber value is not passing from view to controller
Analyst_SQL
3,531
Reputation points
I am fetching record Enrollnumber from database ,using below class
public class RecordID
{
SqlConnection con = new SqlConnection("***");
public List<EmpMasterMV> GeneateEmpID()
{
List<EmpMasterMV> item = new List<EmpMasterMV>();
con.Open();
SqlCommand cmd = new SqlCommand("Sp_Lastinsert_Emp_ID", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
var details = new EmpMasterMV();
details.EnrollNumber = int.Parse(rdr["EnrollNumber"].ToString());
item.Add(details);
}
con.Close();
return item;
}
}
In Controller ,enrollnumber value is coming 0 ,which is not fetching from view
public ActionResult CreaterEmployee()
{
empmastmv.EnrollNumbera =(sdb.GeneateEmpID());
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult CreaterEmployee(EmpMasterMV empmastmv)
{
if (ModelState.IsValid)
{
var CheckEmployee = DB.EmpMasters.Where(u => u.EmpName == empmastmv.EmpName.Trim() && u.FatherName == empmastmv.FatherName).FirstOrDefault();
if (CheckEmployee == null)
{
var newemployee = new EmpMaster();
newemployee.EnrollNumber = Convert.ToInt32(empmastmv.EnrollNumbera);
newemployee.EmpName = empmastmv.EmpName;
newemployee.FatherName = empmastmv.FatherName;
newemployee.EMp_Doj = empmastmv.EMp_Doj;
newemployee.Designation_ID = empmastmv.Designation_ID;
newemployee.SecId = empmastmv.SecId;
DB.EmpMasters.Add(newemployee);
DB.SaveChanges();
return RedirectToAction("AllEmployeeList");
}
else
{
ModelState.AddModelError("Employee", "Already Exists..!");
}
}
return View(empmastmv);
public class EmpMasterMV
{
[Display(Name ="ID")]
public int EnrollNumber { get; set; }
[Display(Name = "Employee Name")]
public List<EmpMasterMV> EnrollNumbera { get; set; }
public string EmpName { get; set; }
[DataType(DataType.Date, ErrorMessage = "Date only")]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> JoinDate { get; set; }
public Nullable<System.DateTime> leftdate { get; set; }
public Nullable<int> SecId { get; set; }
[Display(Name = "Department")]
public string Dept_Name { get; set; }
public string Status { get; set; }
public string CNIC { get; set; }
public string FatherName { get; set; }
public string Cell { get; set; }
public string Address { get; set; }
public Nullable<int> Duty_Hours { get; set; }
public Nullable<System.TimeSpan> InTime { get; set; }
public Nullable<int> emp_Del_ID { get; set; }
public Nullable<int> EMP_Salary { get; set; }
public Nullable<int> Designation_ID { get; set; }
public string Designation_Name { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public Nullable<DateTime> EMp_Doj { get; set; }
public string Emp_Education { get; set; }
public Nullable<int> Emp_Deduction { get; set; }
public Nullable<System.DateTime> emp_DOL { get; set; }
public Nullable<System.DateTime> emp_entrydate { get; set; }
public Nullable<System.TimeSpan> emp_time { get; set; }
public string ipAddress { get; set; }
public Nullable<System.DateTime> emp_update { get; set; }
public Nullable<int> emp_OT { get; set; }
public string Allowance { get; set; }
public Nullable<int> Food { get; set; }
public string Remarks { get; set; }
public Nullable<int> Location { get; set; }
public Nullable<int> Trans_charges { get; set; }
public Nullable<int> Trans_Type { get; set; }
public string emp_Join_Status { get; set; }
public Nullable<System.TimeSpan> out_time { get; set; }
public Nullable<int> Adv_Pay { get; set; }
public Nullable<System.DateTime> L_date { get; set; }
}