我可以在数据注释的错误消息中添加一个link吗?

can I add a link in the error message of data annotations?

我的引用 class 中有这个 属性,所以在 Html 中我使用了自动完成搜索,消息显示 "Customer name is required",但我想要在客户不存在的情况下显示 "Customer name is required, to add customer click here"。

我的link应该是这样的:

"click here","ActionName","ControllerName"

[Required(ErrorMessage = "Customer name is required, ")]
[Display(Name = ("Customer"))]
public int CustomerId { get; set; }

你真的需要把它放在你的 DataAnnotation 上吗?你不能直接在你的视图中添加吗?

//查看代码x.cshtml

@if (ViewData.ModelState.IsValidField("CustomerId"))
{
      <a href='@Url.Action("Register","customer")'>Register customer</a>
}