I have 3 models:
public class Student {
public int StudentId { get; set; }
public string StudentName { get; set; }
public string Father { get; set; }
public string PhoneNumber { get; set; }
public string Email { get; set; }
public bool Gender { get; set; }
public int EmployID { get; set; }
public int RankID { get; set; }
public int CollegeID { get; set; }
public string Address { get; set; }
public string Description { get; set; }
public virtual ICollection<StudentCourse> OstadCourses2 { get; set; }
public Student()
{
}
}
public class Course
{
public int CourseId { get; set; }
public string Title { get; set; }
public string Subject { get; set; }
public int Year { get; set; }
public virtual ICollection<StudentCourse> OstadCourses1 { get; set; }
public Course()
{
}
}
public class StudentCourse
{
[Key]
public int StudentCourseId { get; set; }
public int StudentId { get; set; }
public int CourseId { get; set; }
public virtual Ostad Ostad14 { get; set; }
public virtual Course Course14 { get; set; }
public OstadCourse()
{
}
public OstadCourse(int ostadId, int courseId)
{
OstadId = ostadId;
CourseId = courseId;
}
}
I have created list of students. I want to create a view that there is a dropdown for course and list of students with their properties. then we click on button bind Courseid and Student Id in database and a list of student and course was shown?
I have tried. but not success.
3
Answers
Before, I created a model called Student along with a form and a list of students. When I fill out the form, the student is added to my database. Now, I need to add a dropdown list for courses. Below the dropdown list, I want to display a list of students from the database with checkboxes next to each student's name. I want to bind each student to the course chosen from the dropdown list.
In your problem description I understand that there are two situations you may face.
In the first scenario, you need two dropdown lists, one for students and another for courses. After clicking, you want to bind students to specific courses and get the corresponding updated list.
In the second scenario, you want to associate each student with their respective course by selecting from a dropdown in the course column within a student list.
If there is a situation that meets your expectations, please reply in time so that we can better help you.If these situations do not fully address your needs, please feel free to provide further information or share some of the frontend page code.
My view;