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,