Here i want to bind in drop-down from database using modal.But i bind the value using
viewdata. so kindly help how to bind drop-down from database using modals.
DESCRIPTION:-
in controller
List<SelectListItem> list = new List<SelectListItem>(); list.Add(new SelectListItem { Text = "Select Country", Value = "Select Country" });//set default text for DropdownList var cat = (from c in db.Country select c).ToArray();//get data from database using linq for (int i = 0; i < cat.Length; i++) { list.Add(new SelectListItem { Text = cat[i].Country_Name, Value = cat[i].Country_Cde.ToString() }); } ViewData["ViewCountry"] = list; Kindly suggest Explain me how to bind values in drop-down from database using modals.
jothi kumarPosted Jul 28, 2014, 3:17 AM
Anupam SinghPosted Jul 28, 2014, 2:59 AM
refer this thread : http://stackoverflow.com/questions/15402388/how-to-use-dropdownlistfor-in-mvc3-razor-with-model
jothi kumarPosted Jul 28, 2014, 1:31 AM
jothi kumarPosted Jul 28, 2014, 1:30 AM
Guest UserPosted Jul 28, 2014, 12:59 AM
what's causing the NullReference exception? Is it list.Add or when you're assigning list back to Viewdata
jothi kumarPosted Jul 28, 2014, 12:49 AM
Guest UserPosted Jul 27, 2014, 1:14 AM
http://www.codeproject.com/Articles/710776/Introduction-to-ASP-NET-MVC-Model-Binding-An-Absol