Skip to content
Loading
 
  1. public class TestController : Controller  
  2.     {  
  3.         //  
  4.         // GET: /Test/  
  5.         public ActionResult Index()  
  6.         {  
  7.             var list = new List() { "Private(Copyrighted)", "Public Domain", "Creative Commons Licences", "CC Attribution", "CC Attribution Share ALike", "CC Attribution Non-Commercial",    
  8.               "CC Attribution Non-Commercial Share Alike", "CC Attribution Non Directive", "CC Attribution Non-Commercial No Directives" };  
  9.   
  10.             List select_list = new List();  
  11.   
  12.             var query = from li in list  
  13.                         select new SelectListItem()  
  14.                         {  
  15.                             Value = li.ToString(),  
  16.                             Text = li.ToString(),  
  17.                         };  
  18.             select_list = query.ToList();  
  19.             ViewBag.list = select_list;  
  20.             justtt j = new justtt();  
  21.             return View(j);  
  22.         } 
  23. public class justtt
        {
            public string name { get; set; }
        }
+1
  • 0
    Khatoon Hi
     
    Its funny because no matter how much property i try to access it still see it as null. ViewBag.couse on my add watch null. Let me share the new revised code below including multiple model i am using to my View.
    1.   [HttpPost]  
    2.       public ActionResult CourseList()   
    3.        {  
    4.            var course = new List<string>()   
    5.            {  "Private(Copyrighted)","Public Domain", "Creative Commons Licences", "CC Attribution", "CC Attribution Share ALike", "CC Attribution Non-Commercial",  
    6.              "CC Attribution Non-Commercial Share Alike", "CC Attribution Non Directive", "CC Attribution Non-Commercial No Directives"   
    7.            };  
    8.            // List of items here.  
    9.            List select_list = new List();  
    10.   
    11.            var query = from li in course  
    12.                        select  
    13.                        new SelectListItem  
    14.                        {  
    15.                            Value = li.ToString(),  
    16.                            Text = li.ToString(),  
    17.                        };  
    18.            select_list = query.ToList();  
    19.            ViewBag.course = select_list;  
    20.            eNtsaCourseList eCourse = new eNtsaCourseList();  
    21.   
    22.            return View(eCourse);  
    23.   
    24.        }  
    25. / Multiple Model  
    26. public class RegCoursesViewModel  
    27.    {  
    28.        public eNtsaCourses Courses { get; set; }  
    29.        public eNtsaCourseList eCourses { get; set; }  
    30.        public eNtsaDashboardViewModel Dashboard { get; set; }  
    31.        public List lsteNtsaDashboard { get; set; }  
    32.        public RegCoursesViewModel MainModel { get; set; }  
    33.   
    34.    }  
    35.  public class eNtsaCourseList  
    36.    {  
    37.        public string CourseLicence { get; set; }  
    38.        public string Text { get; set; }  
    39.   
    40.        public string Value { get; set; }  
    41.        public string CourseList { get; set; }  
    42.    }  
    43. class="form-group row">  
    44.                                            for="Content-Licence" class="col-sm-3 col-form-label">Content Licence  
    45.                                            class="col-sm-5">  
    46.                                                @Html.DropDownListFor(m=>m.eCourses.CourseLicence, ViewBag.course as List)  
    47.                                              
      
  •                                              
  •  
    0