ASP.NET MVC3 앱이 있으며 뉴스 추가 양식도 있습니다. VS2010에서 기본보기를 만들 때 문자열 데이터에는 텍스트 입력 만 있지만 뉴스 텍스트에는 텍스트 영역이 필요합니다. 면도기 구문으로 어떻게 할 수 있습니까?
텍스트 입력은 다음과 같습니다 :
@Html.EditorFor(model => model.Text)
답변
다음 [DataType]
과 같이 뷰 모델 의 속성을 사용할 수 있습니다 .
public class MyViewModel
{
[DataType(DataType.MultilineText)]
public string Text { get; set; }
}
그런 다음 컨트롤러를 가질 수 있습니다.
public class HomeController : Controller
{
public ActionResult Index()
{
return View(new MyViewModel());
}
}
그리고 당신이 원하는 것을하는보기 :
@model AppName.Models.MyViewModel
@using (Html.BeginForm())
{
@Html.EditorFor(x => x.Text)
<input type="submit" value="OK" />
}
답변
누군가 속성 추가 (특히 ‘행’과 ‘콜’)에 대해 물었습니다. Razor를 사용하는 경우 다음을 수행하면됩니다.
@Html.TextAreaFor(model => model.Text, new { cols = 35, @rows = 3 })
그것은 나를 위해 작동합니다. ‘@’은 키워드를 이스케이프하여 변수 / 속성으로 취급하는 데 사용됩니다.
답변
@Html.TextAreaFor(model => model.Text)
답변
로 모델을 선언하십시오
[DataType(DataType.MultilineText)]
public string urString { get; set; }
그런 다음 .cshtml에서 아래와 같이 편집기를 사용할 수 있습니다. TextArea 크기 에 @cols 및 @rows 를 사용할 수 있습니다
@Html.EditorFor(model => model.urString, new { htmlAttributes = new { @class = "",@cols = 35, @rows = 3 } })
감사 !