Hi,
I'm using the infragistics MVC extensions for creating a combo box in my MVC3 application.
@(Html.Infragistics().ComboFor(model => model.StatusID) .Default() //My own extension method (to set width, height, etc) .NullText("Select Status") .ValueKeyType(ComboDataType.Number) .DataSource(Model.Statuses) //this is an IQueryable<Status> .ValueKey("ID") .TextKey("Description") .DataBind() //Doesn't seem to be nescesary .Render())
I want StatusID to be an int? in my viewmodel (it's for a search component), but it won't bind when I do an POST action. I had to change it to a string to be able to receive a value in my HttpPost method. It appeared as a string "[|7:number:8|]Cancel", which I know could parse, but doesn't make sense to be doing this every time I want a to use a combobox. If I continue like that, I will be polluting my model object and coupling UI implementation.
Is there any way to receive the selected value only as an integer on my model?
Thank You,
Thank you for question.
First version of combo Mvc helper for igCombo attempted to pass to server 3 values:
1. Array of selected indexes2. Array of selected values3. Current (custom) text in field
That implementation required custom format coming from client. However, it did not match with approach of Mvc related to <select> (DropDownList and others).
To make combo compatible with Mvc-<select>, architecture of combo-helper was changed and now only selected value(s) is used. The ViewModel may contain corresponding types such as string, string[], int, double, int[], double[], etc.
Coming service releases should contain that change.
Hi Viktor,
Thank you very much for your response.
I managed to resolve this for now by creating two object; one hidden Html.DropDownFor that comes native with MVC3 and then follow it by an Infragistics combo with the same ID so that it uses the data from the base <select> element generated.
The only issue with this is that I now have two elements in my HTML source with the same ID, but I guess is fine for now.
Regards,