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
Anilananda Chakrabortty
NA
425
78k
MVC Dropdown list bind
May 16 2018 10:53 PM
I am using code first approach
[Table(
"tblDepartment"
)]
public
class
Department
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity), Key]
public
int
id {
get
;
set
; }
[Required(ErrorMessage =
"Plz enter department name"
)]
public
string
deptName {
get
;
set
; }
[Column(TypeName =
"nvarchar"
), MaxLength(500)]
public
string
deptDescriptions {
get
;
set
; }
public
virtual
ICollection<Student> Students {
get
;
set
; }
}
[Table(
"tblStudents"
)]
public
class
Student
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity), Key]
public
int
stu_id {
get
;
set
; }
[Required(ErrorMessage =
"Plz enter Students name"
)]
public
string
stuName {
get
;
set
; }
public
int
age {
get
;
set
; }
// Foreign key
public
int
id {
get
;
set
; }
// Navigation properties
public
virtual
Department Department {
get
;
set
; }
}
here the database context
public
DatabaseContext()
:
base
(
"StudentDatabase"
)
{
Database.SetInitializer<DatabaseContext>(
new
CreateDatabaseIfNotExists<DatabaseContext>());
}
public
DbSet<Department> Departments {
get
;
set
; }
public
DbSet<Student> Student {
get
;
set
; }
First class Departments i completed CRUD operation, but problem with the second class...
I want the department name should display in the Student view page, and when i will submit the details of a student in the database it should save only department id , but in view i want to see all the department name inside a dropdown list , form there i'll select a department and will submit....
i have no idea how to do that ... i am new in MVC ... can anyone help me plz???
Reply
Answers (
4
)
Web API In visual studio 2012
Directly print .rdlc report (without preview) in Asp.Net Mvc