How can I change the size of a multi-line editor-field?

爱⌒轻易说出口 提交于 2020-01-10 22:04:23

问题


I'm working on an MVC project using C#. Right now, I'm trying to customize my views a little, and I'd like to make the text boxes bigger.

I followed the suggestions in this question to move from a single-line to a multi-line text field: Changing the size of Html.TextBox

Now I'm trying to resize that multi-line field, but I'm not sure where or how to do so.

Here are snippets from my Edit view

<div class="editor-label">
     @Html.LabelFor(model => model.Body)
</div>
<div class="editor-field">
     @Html.EditorFor(model => model.Body)
     @Html.ValidationMessageFor(model => model.Body)
</div>

and from my model:

[DataType(DataType.MultilineText)]  
[DisplayName("Body:")]  
public string Body { get; set; }

回答1:


I would do this with CSS:

<div class="editor-multiline-field">
     @Html.EditorFor(model => model.Body)
     @Html.ValidationMessageFor(model => model.Body)
</div>

and then in your CSS file define the width and height to the desired values:

.editor-multiline-field textarea {
    width: 300px;
    height: 200px;
}



回答2:


You can also use @Html.TextArea ou TextAreaFor

@Html.TextAreaFor(model => model.Text, new { cols = 25, @rows = 5 })



回答3:


In MVC 5 you can use

    @Html.TextAreaFor(model => model.body, 5, 50,  new { @class = "form-control" } )

Works nicely!




回答4:


If you are using mvc and bootstrap try this:

@Html.TextAreaFor(model => model.Property, new { @class = "form-control", @rows = 5 })



回答5:


To adhere to a previously created view style, you can also do this:

<div class="col-md-10 editor-multiline-field">



回答6:


try

@Html.TextAreaFor(model => model.Descricao, 5, 50, null)

in View Page




回答7:


I just wanna share in mvc 5

  @Html.EditorFor(model => model.Body, 
                  new {htmlAttributes = new {@style="width:yourdesiredwidth;"}
                   })

or use a custom class



来源:https://stackoverflow.com/questions/5119221/how-can-i-change-the-size-of-a-multi-line-editor-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!