ASP.MVC에서 여러 줄 Editor-For의 열과 행을 어떻게 지정합니까?
ASP.MVC 3에서 여러 줄 EditorFor
(텍스트 영역)에 대한 열과 행을 어떻게 지정 합니까? 을 사용 [UIHint("MultilineText")]
하고 있지만 텍스트 영역에 속성을 추가하는 방법에 대한 문서를 찾을 수 없습니다.
원하는 HTML :
<textarea cols="40" rows="10"></textarea>
내 MVC 3 모델의 관련 부분 :
[UIHint("MultilineText")]
public string Description { get; set; }
내 Razor cshtml의 관련 부분 :
<div class="editor-field">
@Html.EditorFor(model => model.Description)
</div>
View Source에서 얻는 것 :
<div class="editor-field">
<textarea class="text-box multi-line" id="Description" name="Description"></textarea>
</div>
행과 열은 어떻게 설정합니까?
TextAreaFor 사용
@Html.TextAreaFor(model => model.Description, new { @class = "whatever-class", @cols = 80, @rows = 10 })
또는 multi-line
수업에 스타일을 사용하십시오 .
이를 위해 EditorTemplate 을 작성할 수도 있습니다 .
ASP.NET MVC 5에서는 [DataType(DataType.MultilineText)]
특성을 사용할 수 있습니다 . TextArea 태그 를 렌더링합니다 .
public class MyModel
{
[DataType(DataType.MultilineText)]
public string MyField { get; set; }
}
그런 다음보기에서 행을 지정해야하는 경우 다음과 같이 할 수 있습니다.
@Html.EditorFor(model => model.MyField, new { htmlAttributes = new { rows = 10 } })
또는 올바른 오버로드로 TextAreaFor를 사용하십시오.
@Html.TextAreaFor(model => model.MyField, 10, 20, null)
이것은 또한 내가 믿는 적은 노력으로 사용할 수 있습니다 (하지만 MVC 5에 있습니다)
@Html.Description(model => model.Story, 20, 50, new { })
한 가지 옵션은 CSS를 사용하여 텍스트 영역의 스타일을 지정하는 것 같습니다.
.multi-line { height:5em; width:5em; }
Amurra의 대답은 EditorFor를 사용할 때이 클래스가 자동으로 추가된다는 것을 의미하는 것으로 보이지만이를 확인해야합니다.
편집 : 확인, 그렇습니다. 그렇습니다. EditorFor를 사용하려면이 CSS 스타일을 사용하면 원하는 작업을 수행 할 수 있습니다.
<textarea class="text-box multi-line" id="StoreSearchCriteria_Location" name="StoreSearchCriteria.Location">
mvc 5에서
@Html.EditorFor(x => x.Address,
new {htmlAttributes = new {@class = "form-control",
@placeholder = "Complete Address", @cols = 10, @rows = 10 } })
.net VB 에서는 razor 파일에서 다음을 사용하여 열과 행을 제어 할 수 있습니다.
@Html.EditorFor(Function(model) model.generalNotes, New With {.htmlAttributes = New With {.class = "someClassIfYouWant", .rows = 5,.cols=6}})
'developer tip' 카테고리의 다른 글
정수가 범위 내에 있는지 확인하는 방법은 무엇입니까? (0) | 2020.11.13 |
---|---|
Aptana Studio 3에서 원격 호스트에 연결하는 방법 (0) | 2020.11.13 |
Laravel 미들웨어는 컨트롤러에 변수를 반환합니다. (0) | 2020.11.13 |
두 개의 맥. (0) | 2020.11.13 |
python argparse를 접두사없이 상호 배타적 인 그룹 인수로 만드는 방법은 무엇입니까? (0) | 2020.11.13 |