看法:
<td>
@Html.LabelFor(model => model.TypeId) :
</td>
<td>
@Html.DropDownList("TypeId", String.Empty)
</td>
<td>
@Html.ValidationMessageFor(model => model.TypeId)
</td>
控制器:
ViewBag.TypeId = new SelectList(db.Types, "TypeId", "Name", purchaseauthoriserlist.TypeId);
下拉列表中的验证消息说:
"The TypeId field is required."
我想让它说:
"The Name field is required."
我尝试了以下方法:
[MetadataType(typeof(TypeMetaData))]
public partial class Type
{
}
public class TypeMetaData
{
[Display(Name = "Type")]
public int TypeId { get; set; }
}