I have the following set for drop down in asp.net mvc
@Html.DropDownListFor(model => model.DataId, ((IEnumerable<ProgrammeModel>)ViewBag.Data).Select(option => new SelectListItem
{
Text = (option == null ? "None" : option.Name),
Value = option.DataId.ToString(),
Selected = (Model != null) && (option.DataId== Model.DataId)
}), "Choose...", new { Class = "input", id = "DataId"
})
And in model:
[Required(ErrorMessage="The Data field is required.")]
public int DataId { get; set; }
But when the validation happens on form submit I am getting the error message for this field as
The Int32 field is required.
where I was expecting the result as
The Data field is required