I have the following html:
<script type="text/javascript"> var data = [ { 'Label': 'Label1', 'Value': '100'} , { 'Label': 'Label2', 'Value': '200'} ] ; $(document).ready(function () { $("#combo").igCombo({ dataSource: data, textKey: "Label", valueKey: "Value", width: "200px", multiselect: false, mode: "dropdown" }); }); </script> @using (Html.BeginForm("Submit", "Home", new { @id="queuereportform" }, FormMethod.Post)) { <input id="combo" name="combo" /><br /> <input type="submit" name="submit" value="Submit" /> }
My controller has this method:
[HttpPost] public void Submit(FormCollection fc) { System.Diagnostics.Debug.WriteLine(fc["combo"]); }
fc["combo"] is either 'Label1' or 'Label2'
Obviously I'd like it to be '100' or '200'
What am I doing wrong?
Hello Pete,
I was able to reproduce the issue you were describing in a sample. I am doing further testing to find out the cause. I will update you by the end of the day Monday with the progress.
Please let me know if you have any further questions regarding this matter.
Hi Pete,The fc['combo'] returns current value in INPUT with name "combo". That value should be equal to item with textKey like Label1, etc. (whatever end user see).
In order to support Mvc wrappers, the igCombo exposes special option "inputName". That field contains current selected value (or values separated by coma). If application uses Mvc wrapper, then that field is created automatically. If application creates igCombo explicitly, then it may use that field too. Below are steps to implement that:1. Add a hidden input with desired name. It can be the same as id of igCombo. For example, replace your current<input id="combo" name="combo" />by<input id="combo" /><input name="combo" type="hidden" /> 2. Add to igCombo inputName with that name$("#combo").igCombo({ ... inputName: "combo"}Note: inputName also may point to SELECT instead of INPUT and it should work as well.
That's awesome. Thanks Viktor. Worked like a charm.