MVC Grid Dropdowns not displaying text

I'm having a lot of trouble populating the dropdown for editing my MVC grid. The controller seems to be passing the list of statuses to the view ok, but the textbox in the edit dialog shows three blank options.

I've also tried passing the list in using a JS array but with the same result.

[Razor]

    @(Html.EJ().Grid<object>("Grid")
                    .Datasource(ds => ds.URL("ManagerSummaryDataSource").UpdateURL("Update")
                   .Adaptor(AdaptorType.UrlAdaptor))

                    .AllowPaging()
                    .AllowScrolling()
                    .MinWidth(1500)
                    .ScrollSettings(scroll => scroll.Height(200).Width(1200))
                    .EditSettings(edit => { edit.AllowDeleting().AllowEditing().EditMode(EditMode.Dialog).ShowConfirmDialog(); })
                    .EnableRowHover(true)

                    .Columns(col =>
                    {
                        col.Field("App_ID").IsPrimaryKey(true).HeaderText("ID").HeaderTextAlign(TextAlign.Center).TextAlign(TextAlign.Center).Width(25).IsPrimaryKey(true).Add();

                        col.Field("StaffName").HeaderText("Name").Width(150).TextAlign(TextAlign.Left).Add();

                        col.Field("Training_name").HeaderText("Training").HeaderTextAlign(TextAlign.Center).Width(100).TextAlign(TextAlign.Left).Add();

                        col.Field("TL_status").HeaderText("TL Approval").HeaderTextAlign(TextAlign.Center).Width(100).TextAlign(TextAlign.Left).EditType(EditingType.Dropdown).DataSource((List<String>)ViewData["StatusList"]).Add();

                        col.Field("SLT_status").HeaderText("SLT Approval").HeaderTextAlign(TextAlign.Center).Width(100).TextAlign(TextAlign.Left).EditType(EditingType.Dropdown).Add();

                        col.Field("Notes").HeaderText("Notes").Width(250).HeaderTextAlign(TextAlign.Center).TextAlign(TextAlign.Left).EditType(EditingType.String).Add();

                    }).ClientSideEvents(eve => { eve.Create("create"); })



    )

[Controller]

namespace CQED.Controllers
{
    public class ApprovalController : Controller
    {

        private IStaffRepository StaffRepo;
        private IAppRepository AppRepo;

        public ApprovalController()
        {
            this.StaffRepo = new StaffRepository(new CQED_DB());
            this.AppRepo = new AppRepository(new CQED_DB());
        }

        List<Status> StatusList = new List<Status>();
        public ActionResult Approval()
        {
            StatusList.Add(new Status { id = 1, description = "Pending" });
            StatusList.Add(new Status { id = 2, description = "Approved" });
            StatusList.Add(new Status { id = 3, description = "Declined" });

           ViewData["StatusList"] = StatusList;
                       

            return View();
        }


        public ActionResult ManagerSummaryDataSource(DataManager dm) 
        {
            if (StaffRepo.GetRoleForStaff(Uname) == 2 || StaffRepo.GetRoleForStaff(Uname) == 4)
            {

                var DataSource = new AppRepository().SelectByStaffID(StaffRepo.GetStaffID(Uname)).ToList();
                DataResult result = new DataResult();
                result.result = DataSource.Skip(dm.Skip).Take(dm.Take).ToList();
                result.count = DataSource.Count();
                return Json(result, JsonRequestBehavior.AllowGet);
              
                
            }

            else return null;
        }
       
        [HttpPost]
        public ActionResult Update(Application value)
        {
            using (CQED_DB CQEDDB = new CQED_DB())
            {
                AppRepo.Update(value,value.App_ID);

                var data = AppRepo.SelectByStaffID(StaffRepo.GetStaffID(Uname));
                return Json(data, JsonRequestBehavior.AllowGet);
            }
          
        }

        public class DataResult
        {
            public IEnumerable<Application> result  { get; set; }
            public int count { get; set; }
        }

        public class Status
        {
            public int id { get; set; }
            public string description { get; set; }

        }
    }
}




1 Reply

KM Kuralarasan Muthusamy Syncfusion Team April 23, 2018 04:41 PM UTC

Hi Luke, 

Thanks for contacting Syncfusion support. 

We have analyzed your code and we found that dropdown list values does not shows while editing the grid. The mentioned issue occurs if the dataSource is not properly set for the dropdown columns. we have modified your code with your requirement. Also we have prepared the sample with your requirement. 

Please refer the following code example: 

 
View Page: 
 
@(Html.EJ().Grid<OrdersView>("Grid") 
 
                         ..... 
 
                    .Columns(col => 
                    { 
                         
                        col.Field("ShipCountry").HeaderText("ShipCountry").EditType(EditingType.Dropdown).DataSource((IEnumerable<object>)ViewData["data"]).Width(90).Add(); 
 
                    }) 
) 
 
 
 
Controller Side: 
 
namespace Sample145862.Controllers 
{ 
    public class HomeController : Controller 
    { 
        public ActionResult Index() 
        { 
            var DataSource2 = new NorthwindDataContext().OrdersViews.ToList(); 
            ViewBag.dataSource2 = DataSource2; 
            Approval(); 
            return View(); 
        } 
 
        List<Status> StatusList = new List<Status>(); 
        public ActionResult Approval() 
        { 
            StatusList.Add(new Status { value = 1, text = "Pending" }); 
            StatusList.Add(new Status { value = 2, text = "Approved" }); 
            StatusList.Add(new Status { value = 3, text = "Declined" }); 
            ViewData["data"] = StatusList; 
            return View(); 
        } 
    } 
} 


 
Please refer the following link to sample: 



Regards, 
Kuralarasan M. 


Loader.
Up arrow icon