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
990
How to populate datasource of igCombo separate from the Model
posted

I have a parital view that populates several igCombo controls, but i have a custom model that i'm passing in to use to render the controls in the view using "@Html.LabelFor..." and "@(Html.Infragistics().ComboFor...", among other things.  The model type that i define is custom, but when i set the Datasource of my igCombo to something like "Url.Action("GetCountryCodes", "Reports")", i get an exception saying that the model item passed into the dictionary is of type 'System.Linq.EnumerableQuery`1[System.Data.DataRow]', but this dictionary requires a model item of type 'CustomReportModel'.

How do i populate my igCombo if i'm already using a model in the view to render the controls?  Furthermore, i have several igCombos in the partial view, so how do i populate all of them in this way?

thanks,

wvusaf

Parents
  • 20255
    Offline posted

    Hello,

    Thank you for contacting us!

    If you want to use ComboFor, you will need to pass the Item which you want to be initially selected when combo is loaded. For example, I have created a custom model Locations and my controller is passing data source with Location List. Have a look at the code snippet below:

    View:

    @(Html.Infragistics().ComboFor(item => item.LocationID)

    .Width("200px")

    .DataSourceUrl(Url.Action("ComboDataLocation"))

    .ValueKey("LocationID")

    .TextKey("Country")

    .DataBind()

    .Render()

    )

    Controller:

    public ActionResult Index()

    {

    Factory factory = new Factory();

    List<ComboExample.Models.Location> locations = factory.GetLocation();

    return View("ComboExample.Models.Location", locations[4]);

    }

    [ComboDataSourceAction]

    [ActionName("ComboDataLocation")]

    public ActionResult ComboDataLocation()

    {

    Factory factory = new Factory();

    List<ComboExample.Models.Location> locations = factory.GetLocation();

    return View(locations.AsEnumerable<ComboExample.Models.Location>());

    }

    Model:

    public class Location

    {

    public Location(int LocationID, string Country, string Text)

    {

    this.LocationID = LocationID;

    this.Country = Country;

    this.Text = Text;

    }

    public Location()

    {

    }

    public int LocationID { get; set; }

    public string Country { get; set; }

    public string Text { get; set; }

    public IEnumerable<Location> Locations { get; set; }

    }

Reply Children