我有這樣的代碼在我看來:Html.DropDownList沒有驗證
<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中的錯誤。你可以幫我嗎?
向我們展示您的模型 – archil
您可以在視圖頂部添加@ Html.ValidationSummary(),並向我們展示您得到的確切錯誤。你確定它與Type屬性有關嗎? – archil
它不顯示,直到它的帖子任何驗證消息並且在[驗證所需的選擇中的DropDownList]的控制器 – karaxuna