Conversion of selectlist into stringIYIndu Yadav9yAsked Apr 24, 2017, 4:33 AM EDT5 answersShareLinkedInXCopy linkSaveconvert type 'System.Web.Mvc.SelectList' to 'System.Collections.Generic.List......how to send the data of controller to view using viewbag in mvc.................
Conversion of selectlist into stringIYIndu Yadav9yAsked Apr 24, 2017, 4:33 AM EDT5 answersShareLinkedInXCopy linkSaveconvert type 'System.Web.Mvc.SelectList' to 'System.Collections.Generic.List......how to send the data of controller to view using viewbag in mvc.................
Ramesh PalanivelRank #372 · 6.8K reputation9y agoPosted Apr 24, 2017, 5:00 AM EDT+1Hi Indu, Kindly share your controller code, I will help you+1
IYIndu YadavRank #5,629 · 292 reputation9y agoPosted Apr 24, 2017, 5:06 AM EDT+1 public ActionResult EditData(int Candidate_Id=0) { Application model = context.Applications.Find(Candidate_Id); var x = (from c in context.Applications where c.Candidate_Id == Candidate_Id select c).FirstOrDefault(); string gc = (from sub in context.Applications where sub.Candidate_Id == Candidate_Id select sub.appearing_class).First(); ViewBag.appearing_class = new SelectList(gc); model.Candidate_Id = x.Candidate_Id; return View(model); } VIEW : IF You Are Appearing Condidate @Html.DropDownList("gc", ((List)ViewBag.appearing_class).Select(m => new SelectListItem { Text = m, Value = m })) @*@Html.DropDownListFor(model => model.appearing_class, new SelectList(ViewBag.appearing_class as System.Collections.IEnumerable, "appearing_class", "appearing_class"), "select", new { @id = "AppearingClass", @name = "AppearingClass" })*@+1Ramesh PalanivelRank #372 · 6.8K reputation9y agoPosted Apr 24, 2017, 5:15 AM EDT+1Hi Indu, Try this code, var gc = (from sub in context.Applications where sub.Candidate_Id == Candidate_Id select sub.appearing_class).toList(); ViewBag.appearing_class = new SelectList(gc,context.Applications.appearing_class,context.Applications.appearing_class,0); +1Manas MohapatraRank #182 · 13.2K reputation9y agoPosted Apr 24, 2017, 5:25 AM EDT+1Because DropDownList does not accept a list of strings. It accepts IEnumerable. Follow below links that may help you: http://www.c-sharpcorner.com/UploadFile/4d9083/binding-dropdownlist-in-mvc-in-various-ways-in-mvc-with-data/ http://dotnetmentors.com/mvc/how-to-bind-dropdownlist-in-asp-net-mvc-application.aspx +1IYIndu YadavRank #5,629 · 292 reputation9y agoPosted Apr 24, 2017, 8:42 PM EDT+1update operation between two dropdownlist..........means dropdown shows the selected data when we perform update query.+1Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ramesh PalanivelRank #372 · 6.8K reputation9y agoPosted Apr 24, 2017, 5:15 AM EDT+1Hi Indu, Try this code, var gc = (from sub in context.Applications where sub.Candidate_Id == Candidate_Id select sub.appearing_class).toList(); ViewBag.appearing_class = new SelectList(gc,context.Applications.appearing_class,context.Applications.appearing_class,0); +1
Manas MohapatraRank #182 · 13.2K reputation9y agoPosted Apr 24, 2017, 5:25 AM EDT+1Because DropDownList does not accept a list of strings. It accepts IEnumerable. Follow below links that may help you: http://www.c-sharpcorner.com/UploadFile/4d9083/binding-dropdownlist-in-mvc-in-various-ways-in-mvc-with-data/ http://dotnetmentors.com/mvc/how-to-bind-dropdownlist-in-asp-net-mvc-application.aspx +1
IYIndu YadavRank #5,629 · 292 reputation9y agoPosted Apr 24, 2017, 8:42 PM EDT+1update operation between two dropdownlist..........means dropdown shows the selected data when we perform update query.+1
Ramesh PalanivelRank #372 · 6.8K reputationPosted Apr 24, 2017, 5:00 AM EDT
Indu YadavRank #5,629 · 292 reputationPosted Apr 24, 2017, 5:06 AM EDT
Ramesh PalanivelRank #372 · 6.8K reputationPosted Apr 24, 2017, 5:15 AM EDT
Manas MohapatraRank #182 · 13.2K reputationPosted Apr 24, 2017, 5:25 AM EDT
Indu YadavRank #5,629 · 292 reputationPosted Apr 24, 2017, 8:42 PM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts