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
254
Q: Getting selected value of Combo in HttpPost (MVC3)
posted

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,

Parents
  • 24497
    Verified Answer
    posted

    Hi,

    Thank you for question.

    First version of combo Mvc helper for igCombo attempted to pass to server 3 values:

    1. Array of selected indexes
    2. Array of selected values
    3. 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.

Reply Children
No Data