TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Hussain Hashimi
NA
8
2.3k
MVC with Entity Framework (One to Many relationship)
Jun 14 2019 5:17 AM
Hi,
I am new to MVC, I am trying to create "code first" mvc form and have created two classes as follows.
public class Department
{
public int DepartmentId { get; set; }
[Required()]
[StringLength(150, MinimumLength =10)]
public String DepartmentName { get; set; }
public virtual List<Employee> Employee { get; set; }
}
public class Employee
{
public int EmployeeId { get; set; }
[Required()]
[StringLength(150, MinimumLength =4)]
public String FName { get; set; }
[Required()]
[StringLength(150, MinimumLength = 4)]
public String LName { get; set; }
public virtual Department Department { get; set; }
}
Now, when I create a controller for these classes, and it creates the View automatically, I get the input / details / delete etc automatically.
But when I go to add new employee page, it displays the field's for First name and Last name, but doesn't display the selection for the department.
What I want to do ideally is:
Step1: Go to Departments and Add a couple of departments (say department 1, department 2, department 3 ...)
Step2: Go to employee page and add employee (enter employee first name, last name, and select the department from a drop down list)
so that question is how to display the drop down list for the departments, if it is not automatically created.
thank you .
Reply
Answers (
1
)
What are all ways the GET request can be accessed?
Sir i have one error on GYM project