Hi @عبدالمجيد العتيبي ,
From your view code, I think when you submit the form, the date and the selected Employee and Shifts should keep the relationships, is that correct? But by using the EmpShifts model, when submit the form, we can't keep relationships. So, I suggest you could create a new model to store the date, employeeid and shiftid (you can also add other property).
Change the model like this:
public class EmpShifts
{
public int DepartmentID { get; set; }
public List<Departments>? Departments { get; set; } //used to populate the Departments DropDownList.
public List<Employee>? Employees { get; set; } = new List<Employee>();//used to populate the Employee DropDownList.
public List<Shifts>? Shifts { get; set; } = new List<Shifts>();//used to populate the Shifts DropDownList.
public List<string> Dates { get; set; } //use for statement to loop the date
public List<EmpShiftSelected>? EmpShiftSelected { get; set; } //use this list to transfer the table row data to the controller.
public int EmployeeID { get; set; }
public int ShiftsID { get; set; }
}
public class EmpShiftSelected
{
public string Date { get; set; }
public int EmployeeID { get; set; }
public int ShiftsID { get; set; }
}
Then, in the controller:
And the View code like this: pay attention to the name attribute.
You can view the controller and view code from here: 258587-sourcecode.txt
After that the result as below:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion