2011-11-29 4 views
0

내 프로젝트를 위해 jQuery에서 많은 코딩 작업을하고 있지만 For 접미사가있는 Helper에서 genereated 매개 변수 이름을 얻는 데 도움이 필요합니다.MVC3 - DataAnnotation - propertys 이름

내가 할 경우 :

Html.TextBoxFor(model => model.SomeTextParameter) 

순수 HTML로이 생성의 ID : "SomeTextParameter". jQuery에서 사용하는 모든 장소에서 자동으로 생성 된 ID를 얻고 싶습니다. 그렇게하는 방법?

또는, 난 항상 수동으로 실시 "를"없이 도우미를 사용하여 이름이다 지정할 수 있습니다

Html.TextBox("SomeTextParameter", this.Model.SomeTextParameter) 

을이 경우에 나는 쉬운 ID를 제어 할 수 있습니다하지만 난 다음 레이블 데이터 주석을 사용할 때 찾아 [Display(Name = "Really important text parameter")]Html.Label("SomeTextParameterLabel", <what to enter here?>)으로 연결하는 또 다른 문제

내가 사용하는 경우 :

Html.LabelFor(model => model.SomeTextParameter) 

그것은 내가 원하는대로 표시 그래서 이름을 표시 결합한다.

모든 아이디어를 어떻게 1 또는 2 문제를 해결할 수 있습니까?

답변

1
public class LogOnModel 
{ 
    [Required] 
    [Display(Name = "User name")] 
    public string UserName { get; set; } 

    [Required] 
    [DataType(DataType.Password)] 
    [Display(Name = "Password")] 
    public string Password { get; set; } 

    [Display(Name = "Remember me?")] 
    public bool RememberMe { get; set; } 
} 

<ol> 
    <li> 
     @Html.LabelFor(m => m.UserName) 
     @Html.TextBoxFor(m => m.UserName) 
     @Html.ValidationMessageFor(m => m.UserName) 
    </li> 
    <li> 
     @Html.LabelFor(m => m.Password) 
     @Html.PasswordFor(m => m.Password) 
     @Html.ValidationMessageFor(m => m.Password) 
    </li> 
    <li> 
     @Html.CheckBoxFor(m => m.RememberMe) 
     @Html.LabelFor(m => m.RememberMe, new { @class = "checkbox" }) 
    </li> 
</ol> 
를 사용하여 아이디를 생성 얻을 수 있어야 유용합니다
관련 문제