Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
55
DataSourceURL doesn't seem to work for me for a Combo in a grid
posted

Hello-

I'm struggling a little bit with the grid.  I have it all working fairly nicely and now I want to put some dropdowns in.  The samples all seem to use options.DataSource([object]) and not .DataSourceUrl.  When I use DataSourceUrl, I can see the Controller method being called.

The difficulty I'm having is that no matter what I return, the dropdown is empty.  I used the same Controller pattern as the DataSourceUrl for the Grid:

[GridDataSourceAction]
public ActionResult GetAccounts()
{
    using (var cont = new Models.MyDBEntities())
    {
         var accts = cont.accounts.Select(acct => new { AccountCode = acct.AccountCode, AccountName = acct.AccountName }).ToList();
         return View(accts.AsQueryable());

     }
}

But no matter what I return (whether it's IQueryable<T> or not), nothing winds up in the dropdown.

Parents
No Data
Reply
  • 765
    Suggested Answer
    posted

    Hi efanstay

    i solved this problem many time ago, this is the code of my combo():

    @(Html.Infragistics()
    .ComboFor(model => model.idEstado)
    .ID("ddEstados")
    .EnableClearButton(false)
    .DropDownButtonTitle("Estados")
    .Mode(ComboMode.DropDown)
    .TextKey("Nombre")
    .ValueKey("idEstado")
    .Width("210px")
    .DataSource(@Url.Action("GetEstados"))
    .DataBind()
    .Render())

    and my controller action look like this:

    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult GetEstados()
    {
     LargeJsonResult DataView = new LargeJsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet };
      DataView.Data = from p in da.Estados
       orderby p.Nombre
       select p;
      return DataView;
    }

    really i hope this can help you.

    Regards.

    Christhian

Children
No Data