I have created model class and controller related to a database table and want to populate a dropdown list from another table. my model and controller code is below:-
Imports System.Data.Entity
Namespace employee1
Public Class EmployeeController
Inherits System.Web.Mvc.Controller
Private db As New EmployeeDBContext
'
' GET: /Employee/
Function Index(ByVal sortOrder As String) As ActionResult
ViewBag.LastNameSortParm = If(String.IsNullOrEmpty(sortOrder), "LastName_desc", String.Empty)
Dim Employee = From e In db.Employee Select e
Select Case sortOrder
Case "LastName_desc"
Employee = Employee.OrderByDescending(Function(e) e.LastName)
Case Else
Employee = Employee.OrderBy(Function(e) e.LastName)
End Select
Return View(Employee.ToList())
End Function
'
' GET: /Employee/Details/5
Function Details(Optional ByVal id As Integer = Nothing) As ActionResult
Dim employeemodel As EmployeeModel = db.Employee.Find(id)
If IsNothing(employeemodel) Then
Return HttpNotFound()
End If
Return View(employeemodel)
End Function
'
' GET: /Employee/Create
Function Create() As ActionResult
Return View()
End Function
and this is my model
Imports System.Data.Entity
Public Class EmployeeModel
Public Property ID() As Integer
Public Property CompanyCode() As String
Public Property FirstName() As String
Public Property LastName() As String
Public Property DeptNum() As String
Public Property Status() As Char
Public Property txtCity() As String
Public Property txtState() As String
Public Property txtZip() As String
Public Property txtPhone() As String
Public Property txtPhoneExt() As String
Public Property LastReviewDate() As Date
Public Property HireDate() As Date
End Class
Public Class EmployeeDBContext
Inherits DbContext
Public Property Employee() As DbSet(Of EmployeeModel)
End Class
I want a dropdown list in create view for status from another table named IDStatus view is like
@Using Html.BeginForm()
@Html.ValidationSummary(True)
@<fieldset>
<legend>EmployeeModel</legend>
<div class="editor-label">
@Html.LabelFor(Function(model) model.CompanyCode)
</div>
<div class="editor-field">
@Html.EditorFor(Function(model) model.CompanyCode)
@Html.ValidationMessageFor
</div>
<!-- how do i use dropdown list here which is from different table?-->
</fieldset>
End Using