所以当我让DisplayAttribute在我的模型中装饰一处房产时.
[Required, Display(Name = "Some Name")]
public string SomeProperty { get; set; }在使用ValidationMessageFor助手时,我不再获得该字段的验证消息。
@Html.ValidationMessageFor(model => model.SomeProperty)奇怪的是,如果我使用指定消息的重载,我仍然得不到消息。有人知道这是怎么回事吗?
发布于 2011-04-26 07:35:56
无法复制。
型号:
public class MyViewModel
{
[Required, Display(Name = "Some Name")]
public string SomeProperty { get; set; }
}主计长:
public class HomeController : Controller
{
public ActionResult Index()
{
var model = new MyViewModel();
return View(model);
}
[HttpPost]
public ActionResult Index(MyViewModel model)
{
return View(model);
}
}查看:
@model MyViewModel
@using (Html.BeginForm())
{
@Html.LabelFor(x => x.SomeProperty)
@Html.EditorFor(x => x.SomeProperty)
@Html.ValidationMessageFor(x => x.SomeProperty)
<input type="submit" value="OK" />
}当表单提交时,如果字段为空,则验证错误消息将正确显示。
https://stackoverflow.com/questions/5782648
复制相似问题