// 특정 부서 정보를 Select에 바인딩, 
// 올드 데이터가 NULL 값을 포함할 경우에는 수작업으로 구성
var departments = _context.Departments; 
ViewData["Departments"] = departments;
if (personnel.Department != null)
{
    ViewData["DepartmentId"] = personnel.Department;
}
ViewData["DepartmentId"] = "0";

 

<select class="form-control" asp-for="Department">
    @foreach (var po in ViewBag.Departments)
    {
        if (po.ID.ToString() == ViewBag.DepartmentId)
        {
            <option selected value="@po.ID">@po.Name</option>
        }
        else
        {
            <option value="@po.ID">@po.Name</option>
        }
    }
</select>

 

Comments


Comments are closed