tags:

views:

103

answers:

1

I am passing a optionLabel into the Html.DropDownList helper (taken from this SO question):

<%=Html.DropDownList("PO.Vendor.VendorId", this.Model.Vendors, "-- add a new vendor --")%>

That produces markup with an option of value 0 with the text "-- add a new vendor --", which is exactly what I want. However, if that option is selected and posted, a validation error is thrown.

Is there way to turn off this automatic validation when using an optionLabel?

A: 

The code snippet that you posted doesn't have anything to do with the validation being performed. You could easily just write out all the options in the list manually and you'd still be getting the validation error.

Without seeing the code that is performing the validation, it's hard to tell you how to turn it off. If you're using the reflection-based "UpdateModel()" like in NerdDinner, you'll need to add some code to remove/change that posted value.

Wherever your validation code is, you'll have to work something out to ignore that value.

womp
ahh, yes, your right. I am using the default model binder for a simple parent->child linq2sql object, so my issue isn't related to the helper function. thanks.
ericvg
one more thing: in my original question I said it produced markup with a value of 0. thats in correct. its an empty string, which results in the model binder throwing the error.
ericvg