I have this code in my view:
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"type="text/javascript"></script>
...
<div class="modal_label">
@Html.LabelFor(model => model.Organization.Type)
</div>
<div class="modal_field">
@Html.DropDownListFor(model => model.Organization.Type, (IEnumerable<SelectListItem>)ViewBag.TypeList, String.Empty)
@Html.ValidationMessageFor(model => model.Organization.Type)
</div>
If I change @Html.DropDownFor to @Html.EditorFor, then validation is working, but in this case I have following html rendered:
<select id="Organization_Type" name="Organization.Type" class="valid">
...
</select>
Here is my model:
[MetadataType(typeof(OrganizationMetaData))]
public partial class Organization
{
}
public class OrganizationMetaData
{
[Required(ErrorMessageResourceType = typeof(CCMESResources.ResourceErrors),ErrorMessageResourceName = "ValueIsRequired")]
public int Type { get; set; }
}
When the form posts, there ARE errors in ModelState. Can you help me?