在我看来,我有这段代码:
<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>
如果我将@Html.DropDownFor 更改为@Html.EditorFor,则验证工作正常,但在这种情况下,我呈现了以下 html:
<select id="Organization_Type" name="Organization.Type" class="valid">
...
</select>
这是我的模型:
[MetadataType(typeof(OrganizationMetaData))]
public partial class Organization
{
}
public class OrganizationMetaData
{
[Required(ErrorMessageResourceType = typeof(CCMESResources.ResourceErrors),ErrorMessageResourceName = "ValueIsRequired")]
public int Type { get; set; }
}
当表单发布时,ModelState 中有错误。你能帮助我吗?