ahmed salah

ahmed salah

  • NA
  • 530
  • 148k

How to add dropdown YearID in current model section

Dec 1 2016 3:38 PM
What I need
I need to add drop down YearID from model Year to
current model section with Formate bootstrap as (Replace departID WITH YearID)
I work in mvc 5 visual studio 2015  and i need to get drop down list from another model
Current model name is Section:
  1. namespace UniversityData.Models  
  2. {  
  3.   
  4.    [Table("Section")]  
  5.     public partial class Section  
  6.     {  
  7.         public Section()  
  8.         {  
  9.   
  10.         }  
  11.          
  12.          
  13.         [DatabaseGenerated(DatabaseGeneratedOption.Identity)]  
  14.   
  15.         [Key]  
  16.   
  17.         public int SecID { getset; }  
  18.   
  19.         [Required]  
  20.         [StringLength(50)]  
  21.         public string SecName{ getset; }  
  22.          
  23.         [ForeignKey("Department")]  
  24.         [DisplayName("DepartmentName")]  
  25.         public int departID { getset; }  
  26.     }  
  27. }  
my code to drop down departID inside my current model section  with bootstrap is : 
  1. class="form-group">  
  2.           @Html.LabelFor(model => model.departID, "DepartmentName", htmlAttributes: new { @class = "control-label col-md-2" })  
  3.           class="col-md-10">  
  4.               @Html.DropDownList("departID"null, htmlAttributes: new { @class = "form-control" })  
  5.               @Html.ValidationMessageFor(model => model.departID, ""new { @class = "text-danger" })  
  6.           
Another model Year I want to generate dropdown to it 
  1.  [Table("Year")]  
  2.     public partial class Year  
  3.     {  
  4.         public Year()  
  5.         {  
  6.          this.department = new HashSet();  
  7.   
  8.         }  
  9.         [DatabaseGenerated(DatabaseGeneratedOption.Identity)]  
  10.   
  11.         [Key]  
  12.         public int YearID { getset; }  
  13.         [Required]  
  14.         [StringLength(50)]  
  15.   
  16.         public string YearName { getset; }  
  17.         
  18.     }  
  19. }  
What I need
 
I need to add drop down YearID from model Year to
current model section with Formate bootstrap as (departID BOOTSTRP dropdown)  
 

Answers (1)