-1

看法:

<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; }

} 
4

2 回答 2

1

添加:

[Required(ErrorMessage = "The Name field is required.")]

TypeId模型中的声明。

于 2013-09-06T10:45:58.317 回答
0

添加:

[DisplayName("Name")]

在视图模型中声明 TypeID 或将标签更改为:

@Html.LabelFor(model => model.TypeID, "Name")

于 2013-09-06T08:16:53.257 回答