2011-04-25 5 views
0

을 해제DisplayAttribute는 ... 그래서 확인 메시지

[Required, Display(Name = "Some Name")] 
public string SomeProperty { get; set; } 
ValidationMessageFor 도우미

를 사용하는 경우

나는 더 이상 필드에 대한 검증 메시지가 없습니다

@Html.ValidationMessageFor(model => model.SomeProperty) 

그리고 이상한 점은 메시지를 지정하는 오버로드를 사용하는 경우입니다. 여전히 메시지가 나타나지 않습니다.. 여기에 무슨 일이 일어나는 지 아는 사람이 있습니까?

답변

0

다시 작성할 수 없습니다.

모델 :

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" /> 
} 

.

+0

내가 추가 할 수있는 유일한 다른 점은 형식 (HttpPostedFileBase)에 대한 편집기 템플릿이 있고 입력이 type = file이라는 것입니다. 나는 그것을 작동시킬 수 없었다. 필드가 빨간색으로 바뀌지 만 (기본 CSS 스타일) 메시지는 표시되지 않습니다. – JasonCoder