Skip to content
Loading
 Step 2.Models and Controller Action
  1. public class Student  
  2.    {  
  3.        public int Id { get; set; }  
  4.        public string Name { get; set; }  
  5.        public int CourseId { get; set; }  
  6.    }  
  7.    public class Course  
  8.    {  
  9.        public int Id { get; set; }  
  10.        public string Name { get; set; }  
  11.    } 
  1. public ActionResult cascadeDisplay()  
  2.        {  
  3.            List courses = new List()  
  4.            {   
  5.              new Course(){Id=1,Name="Asp.Net"},  
  6.              new Course(){Id=2,Name="Jquery"},  
  7.            };  
  8.            var list = courses.Select(x => new SelectListItem {   
  9.             Text=x.Name,  
  10.             Value=Convert.ToString(x.Id),  
  11.             Selected=false  
  12.              
  13.            });  
  14.            ViewBag.data = list;  
  15.            return View();  
  16.        }  
  17.        public ActionResult getStudentByCourse(int Id)  
  18.        {  
  19.            List studentList = new List(){  
  20.                new Student(){Id=1,Name="Sachin",CourseId=1},  
  21.                 new Student(){Id=2,Name="Arjun",CourseId=2},  
  22.                  new Student(){Id=3,Name="Vikash",CourseId=1},  
  23.                  new Student(){Id=4,Name="Pocha",CourseId=2},  
  24.            };  
  25.            var students = studentList.Where(x=>x.CourseId==Id);  
  26.            return Json(students,JsonRequestBehavior.AllowGet);  
  27.        } 
+2
  • Salman Beg
    +1
    Check this link also, https://www.c-sharpcorner.com/UploadFile/4d9083/creating-simple-cascading-dropdownlist-in-mvc-4-using-razor/ https://www.c-sharpcorner.com/UploadFile/sourabh_mishra1/cascading-dropdownlist-in-Asp-Net-mvc/
    +1
  • Harsh Shah
    +1
    Try this link...
     
    https://www.aspsnippets.com/Articles/Implement-Cascading-Dependent-DropDownLists-without-jQuery-in-ASPNet-MVC.aspx 
    +1
  • +1
    Yes @Sachin I beginner web technologies, Thanks helping(to reply you in messages I have no inuf permissions it was asking me to make at least 100 points to reply your message thank you so much for helping nature). Thank u all for your help
    +1
  • Jignesh Kumar
    +1
    Hi Sanjay,
     
    Please refer this article which will help you to build cascading dropdown step by step,
     
    https://www.c-sharpcorner.com/blogs/cascading-dropdownlist-in-asp-net-mvc 
    https://www.aspsnippets.com/Articles/Implement-Cascading-Dependent-DropDownLists-without-jQuery-in-ASPNet-MVC.aspx 
    https://www.c-sharpcorner.com/UploadFile/sourabh_mishra1/cascading-dropdownlist-in-Asp-Net-mvc/ 
    +1