我想从编辑记录中的数据库中获取DropDown值,但我没有找到任何解决方案,请给我一些建议。
修改 这是Controller actionResult
public ActionResult Edit(int? id){
var editRecords = (from objDepartment in db.Departments
join objStudent in db.Studentts on objDepartment.Department_id equals objStudent.Dept_id
where objStudent.Student_id == id
select new Student_Department_Model
{
Student_id = objStudent.Student_id,
Stu_Name = objStudent.Stu_Name,
Stu_Age = objStudent.Stu_Age,
University_Dropdown = objStudent.University_Dropdown,
CourseName = objStudent.Course_Name,
Department_id = objDepartment.Department_id,
Department_Name = objDepartment.Department_Name,
Department_Fee =objDepartment.Department_Fee
}).ToList();
return View(editRecords);
}
修改视图
@model List<CompleteCrudOperations.Models.Student_Department_Model>
@{
ViewBag.Title = "Edit";
}
<label>Courses</label>
<select name="CourseName" class="form-control">
<option selected disabled>Select Your's Courses</option>
@foreach (var allCourses in Model)
{
<option>@allCourses.CourseName</option>
}