I have a partial view page where I am using the html dropdownlist control using viewmodel. I haven't specified any validation control on my viewmodel however when I submit the form with default value it asks me to select the value. I can see the source code
of the page which includes class="input-validation-error" I couldn't remove that class file also wondering how/why does it includes when I haven't specified the validation for that field. In my viewmodel the field datatype is GUID. Does it
include validation by default for the GUID? please find my html code below
@Html.DropDownListFor(m => m.Subcategory, new SelectList(Model.SubCategories, "ID", "Name", Model.Subcategory), "Please Select...", new { @id = "subcats" })
The reason you get validation even though you haven't specificed it is because the GUID is non nullable. In Asp.net MVC if you have a non-nullable field (like an int) then that field is considered required and validation attributes are written to the client.
This happens with GUID, int and any field that can't be null. If you don't want validation then you need to use a nullable GUID - "GUID?" as the type in your viewmodel.
kamaleswaran
Member
73 Points
87 Posts
Guid field validation?
Apr 30, 2012 03:53 PM|LINK
Hi
I have a partial view page where I am using the html dropdownlist control using viewmodel. I haven't specified any validation control on my viewmodel however when I submit the form with default value it asks me to select the value. I can see the source code of the page which includes class="input-validation-error" I couldn't remove that class file also wondering how/why does it includes when I haven't specified the validation for that field. In my viewmodel the field datatype is GUID. Does it include validation by default for the GUID? please find my html code below
@Html.DropDownListFor(m => m.Subcategory, new SelectList(Model.SubCategories, "ID", "Name", Model.Subcategory), "Please Select...", new { @id = "subcats" })Kam
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Guid field validation?
Apr 30, 2012 04:06 PM|LINK
The reason you get validation even though you haven't specificed it is because the GUID is non nullable. In Asp.net MVC if you have a non-nullable field (like an int) then that field is considered required and validation attributes are written to the client. This happens with GUID, int and any field that can't be null. If you don't want validation then you need to use a nullable GUID - "GUID?" as the type in your viewmodel.
Blog | Twitter : @Hattan
kamaleswaran
Member
73 Points
87 Posts
Re: Guid field validation?
May 01, 2012 05:49 AM|LINK
Thanks. Wondering is there any other way that I could include value to my option label on the dropdownlist?
Kam
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Guid field validation?
May 01, 2012 03:54 PM|LINK
What do you mean? Can you elabroate on what you trying to do?
Blog | Twitter : @Hattan
kamaleswaran
Member
73 Points
87 Posts
Re: Guid field validation?
May 01, 2012 07:23 PM|LINK
I was refering to this http://forums.asp.net/t/1798744.aspx/1?Inserting+new+row+in+dropdownlistfor+control
I have sorted this now. Thanks!
Kam