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
Hello,
I am glad to hear that I have managed to point you to the right direction.
About your new question, if you mean that when using ComboFor you can set which element to e selected initially after combo is rendered, then my suggestion is to use initialSelectedItems:
http://help.infragistics.com/jQuery/2015.2/ui.igcombo#options:initialSelectedItems
Thank you for the reply. i saw that i was simply missing the [ComboDataSourceAction] attribute on my controller function.
However, now i have another problem. i also tried rendering some comboboxes with javasript instead of the MVC Helper, which means that now my combos show the correct list data, but they aren't connected to the properties within the model. When i use 'ComboFor', it knows that it is for a specific property and when i submit back to the controller, the model property is populated with my selections, but only for the combos that were created using 'ComboFor'.
How can i achieve the same thing using $("#selector").igCombo() ?
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()
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; }